simpod / graphql-request-factory
用于创建与PSR-7兼容的请求以发送到GraphQL服务器的工厂
0.1.5
2023-10-07 12:01 UTC
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-08-28 04:33:53 UTC
README
此工厂通过PSR-17消息工厂创建PSR-7 GraphQL请求,这些工厂可以传递给PSR-18客户端。
安装
将其添加为 Composer 依赖项
composer require simpod/graphql-request-factory
用法
<?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] );
您可以传递 $query
作为 string
或 PSR-7 StreamInterface
。
明白了,但接下来我该怎么做呢?
您可以将它传递给任何支持PSR-7的HTTP客户端。选择哪个客户端由您决定。
Guzzle
http://docs.guzzlephp.org/en/stable/quickstart.html#sending-requests
$response = $client->send($request);
PSR-18客户端(例如HTTPPlug)
https://www.php-fig.org/psr/psr-18/#clientinterface
$response = $client->sendRequest($request);