kinoheld / graphql-commons
为 webonyx/graphql-php 端点提供的常用辅助类。
1.5.0
2020-02-27 09:39 UTC
Requires
- webonyx/graphql-php: ^0.13
README
安装
通过 composer
composer require kinoheld/graphql-commons
提供的类
kinoheld\GraphQLCommons\Context\GenericContext
通用的键/值上下文,用于在类型间存储/检索信息。
// Pass GenericContext to GraphQL::executeQuery
$context = new \kinoheld\GraphQLCommons\Context\GenericContext();
$result = \GraphQL\GraphQL::executeQuery($schema, $source, $rootValue, $context, $variableValues);
// Set context value in resolve method
function($value, $args, GenericContext $context, $info) {
$context->addData('some-key', 'some-value');
}
// Get context value in resolve method
function($value, $args, GenericContext $context, $info) {
$context->getData('some-key'); // 'some-value'
}
kinoheld\GraphQLCommons\Registry\TypeRegistry
内存中的类型注册表,用于只加载一次类型。
// Load MyCustomType into registry and set as field type
$config['fields']['myField']['type'] = \kinoheld\GraphQLCommons\Registry\TypeRegistry::getType('Path\To\MyCustomType');
kinoheld\GraphQLCommons\Type\Scalar\JsonType
JSON 类型,用于输入解析和输出序列化 JSON 字符串。
$config['fields']['myJsonField']['type'] = \kinoheld\GraphQLCommons\Registry\TypeRegistry::getType('kinoheld\GraphQLCommons\Type\Scalar\JsonType');