kinoheld/graphql-commons

Common helper classes for webonyx/graphql-php endpoints.

1.5.0 2020-02-27 09:39 UTC

This package is auto-updated.

Last update: 2024-04-27 19:18:18 UTC


README

Installation

Via composer:

composer require kinoheld/graphql-commons

Provided classes

kinoheld\GraphQLCommons\Context\GenericContext

Generic key/value context to store/retrieve information between types.

// 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

In-memory type registry to load types only once.

// 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 type for input parsing and output serialization of JSON strings.

$config['fields']['myJsonField']['type'] = \kinoheld\GraphQLCommons\Registry\TypeRegistry::getType('kinoheld\GraphQLCommons\Type\Scalar\JsonType');