simpod / graphql-request-factory
Factory to create PSR-7 compatible request to GraphQL server
Fund package maintenance!
simPod
Installs: 44 635
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 4
Forks: 0
Open Issues: 1
Requires
- php: ^8.1
- ext-json: *
- psr/http-factory: ^1.0
- psr/http-message: ^1.0 || ^2.0
- thecodingmachine/safe: ^1.0.2 || ^2
Requires (Dev)
- doctrine/coding-standard: ^12.0
- infection/infection: ^0.27.0
- nyholm/psr7: ^1.2
- phpstan/extension-installer: ^1.1
- phpstan/phpstan: ^1.0.0
- phpstan/phpstan-phpunit: ^1.0.0
- phpstan/phpstan-strict-rules: ^1.0.0
- phpunit/phpunit: ^10.4
- psalm/plugin-phpunit: ^0.18.0
- simpod/php-coveralls-mirror: ^3.0
- vimeo/psalm: ^5.0
This package is auto-updated.
Last update: 2024-11-14 23:32:44 UTC
README
This factory creates PSR-7 GraphQL Request through PSR-17 message factories that you can be passed to PSR-18 client.
Installation
Add as Composer dependency:
composer require simpod/graphql-request-factory
Usage
<?php declare(strict_types=1); namespace YourNs; use SimPod\GraphQLRequestFactory\GraphQLRequestFactory; $requestFactory = new GraphQLRequestFactory(new RequestFactoryInterfaceImpl(), new StreamFactoryInterfaceImpl()); $request = $requestFactory->createRequest( 'https://localhost/graphql', <<<'GRAPHQL' query GetHuman($id: ID!) { human(id: $id) { name appearsIn starships { name } } } GRAPHQL, ['id' => 1] );
You can pass $query
either as a string
or PSR-7 StreamInterface
.
Mkay, but what should I do with the request then?
You can pass it to any HTTP client supporting PSR-7. It's up to you what client you decide to use.
Guzzle
http://docs.guzzlephp.org/en/stable/quickstart.html#sending-requests
$response = $client->send($request);
PSR-18 Client (eg. HTTPPlug)
https://www.php-fig.org/psr/psr-18/#clientinterface
$response = $client->sendRequest($request);