x-graphql/http-schema
最新稳定版本:0.9.0
Composer 安装命令:
composer require x-graphql/http-schema
包简介
Building GraphQL schema over HTTP (aka remote schema)
README 文档
README
Help to build and execute GraphQL schema over HTTP (aka remote schema).
Getting Started
Install this package via Composer
composer require x-graphql/http-schema
This library require PSR-18 Client or Httplug Async Client for sending async requests. Run the command bellow if you don't have yet.
composer require php-http/guzzle7-adapter
Usages
This library offers to you 2 strategy to build schema:
- Build from schema definition language (SDL), this strategy use for limiting fields user can access.
- Build from introspection query, with this strategy it will make a http request for introspecting schema, user can access all the fields.
From SDL
use GraphQL\GraphQL; use XGraphQL\HttpSchema\HttpDelegator; use XGraphQL\HttpSchema\HttpSchemaFactory; $delegator = new HttpDelegator('https://countries.trevorblades.com/'); $schema = HttpSchemaFactory::createFromSDL( $delegator, <<<'SDL' type Query { countries: [Country!]! } type Country { name: String! } SDL ); $result = GraphQL::executeQuery($schema, 'query { countries { name } }'); var_dump($result->toArray());
From introspection query
use GraphQL\GraphQL; use XGraphQL\HttpSchema\HttpDelegator; use XGraphQL\HttpSchema\HttpSchemaFactory; $delegator = new HttpDelegator('https://countries.trevorblades.com/'); $schema = HttpSchemaFactory::createFromIntrospectionQuery($delegator); $result = GraphQL::executeQuery($schema, 'query { countries { name } }'); var_dump($result->toArray());
Caching schema
For optimizing time to build schema from SDL or introspection query, you can put PSR-16 instance to factory methods for caching schema after built:
use XGraphQL\HttpSchema\HttpDelegator; use XGraphQL\HttpSchema\HttpSchemaFactory; /// $psr16Cache = .... $delegator = new HttpDelegator('https://countries.trevorblades.com/'); $schemaFromSDL = HttpSchemaFactory::createFromSDL($delegator, /// $sdl, $psr16Cache); $schemaFromIntrospection = HttpSchemaFactory::createFromIntrospectionQuery($delegator, /// $psr16Cache); /// ........
Credits
Created by Minh Vuong
统计信息
- 总下载量: 34.3k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-02-16