x-graphql/http-schema 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

x-graphql/http-schema

最新稳定版本:0.9.0

Composer 安装命令:

composer require x-graphql/http-schema

包简介

Building GraphQL schema over HTTP (aka remote schema)

README 文档

README

unit tests codecov

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

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-02-16