new Deps
This commit is contained in:
+1
-11
@@ -1,13 +1,3 @@
|
||||
# Config Validation
|
||||
Defining types using arrays may be error-prone, but **graphql-php** provides config validation
|
||||
tool to report when config has unexpected structure.
|
||||
|
||||
This validation tool is **disabled by default** because it is time-consuming operation which only
|
||||
makes sense during development.
|
||||
|
||||
To enable validation - call: `GraphQL\Type\Definition\Config::enableValidation();` in your bootstrap
|
||||
but make sure to restrict it to debug/development mode only.
|
||||
|
||||
# Type Registry
|
||||
**graphql-php** expects that each type in Schema is presented by single instance. Therefore
|
||||
if you define your types as separate PHP classes you need to ensure that each type is referenced only once.
|
||||
@@ -16,4 +6,4 @@ Technically you can create several instances of your type (for example for tests
|
||||
will throw on attempt to add different instances with the same name.
|
||||
|
||||
There are several ways to achieve this depending on your preferences. We provide reference
|
||||
implementation below that introduces TypeRegistry class:
|
||||
implementation below that introduces TypeRegistry class:
|
||||
|
||||
@@ -3,8 +3,10 @@
|
||||
* [Standard Server](executing-queries.md/#using-server) – Out of the box integration with any PSR-7 compatible framework (like [Slim](http://slimframework.com) or [Zend Expressive](http://zendframework.github.io/zend-expressive/)).
|
||||
* [Relay Library for graphql-php](https://github.com/ivome/graphql-relay-php) – Helps construct Relay related schema definitions.
|
||||
* [Lighthouse](https://github.com/nuwave/lighthouse) – Laravel based, uses Schema Definition Language
|
||||
* [Laravel GraphQL](https://github.com/rebing/graphql-laravel) - Laravel wrapper for Facebook's GraphQL
|
||||
* [OverblogGraphQLBundle](https://github.com/overblog/GraphQLBundle) – Bundle for Symfony
|
||||
* [WP-GraphQL](https://github.com/wp-graphql/wp-graphql) - GraphQL API for WordPress
|
||||
* [Siler](https://github.com/leocavalcante/siler) - Straightforward way to map GraphQL SDL to resolver callables, also built-in support for Swoole
|
||||
|
||||
# GraphQL PHP Tools
|
||||
|
||||
@@ -23,3 +25,4 @@
|
||||
* [ChromeiQL](https://chrome.google.com/webstore/detail/chromeiql/fkkiamalmpiidkljmicmjfbieiclmeij)
|
||||
or [GraphiQL Feen](https://chrome.google.com/webstore/detail/graphiql-feen/mcbfdonlkfpbfdpimkjilhdneikhfklp) –
|
||||
GraphiQL as Google Chrome extension
|
||||
* [Altair GraphQL Client](https://altair.sirmuel.design/) - A beautiful feature-rich GraphQL Client for all platforms
|
||||
|
||||
+16
-15
@@ -103,23 +103,25 @@ for a field you simply override this default resolver.
|
||||
**graphql-php** provides following default field resolver:
|
||||
```php
|
||||
<?php
|
||||
function defaultFieldResolver($source, $args, $context, \GraphQL\Type\Definition\ResolveInfo $info)
|
||||
{
|
||||
$fieldName = $info->fieldName;
|
||||
$property = null;
|
||||
function defaultFieldResolver($objectValue, $args, $context, \GraphQL\Type\Definition\ResolveInfo $info)
|
||||
{
|
||||
$fieldName = $info->fieldName;
|
||||
$property = null;
|
||||
|
||||
if (is_array($source) || $source instanceof \ArrayAccess) {
|
||||
if (isset($source[$fieldName])) {
|
||||
$property = $source[$fieldName];
|
||||
}
|
||||
} else if (is_object($source)) {
|
||||
if (isset($source->{$fieldName})) {
|
||||
$property = $source->{$fieldName};
|
||||
if (is_array($objectValue) || $objectValue instanceof \ArrayAccess) {
|
||||
if (isset($objectValue[$fieldName])) {
|
||||
$property = $objectValue[$fieldName];
|
||||
}
|
||||
} elseif (is_object($objectValue)) {
|
||||
if (isset($objectValue->{$fieldName})) {
|
||||
$property = $objectValue->{$fieldName};
|
||||
}
|
||||
}
|
||||
|
||||
return $property instanceof Closure
|
||||
? $property($objectValue, $args, $context, $info)
|
||||
: $property;
|
||||
}
|
||||
|
||||
return $property instanceof Closure ? $property($source, $args, $context, $info) : $property;
|
||||
}
|
||||
```
|
||||
|
||||
As you see it returns value by key (for arrays) or property (for objects).
|
||||
@@ -161,7 +163,6 @@ $userType = new ObjectType([
|
||||
Keep in mind that **field resolver** has precedence over **default field resolver per type** which in turn
|
||||
has precedence over **default field resolver**.
|
||||
|
||||
|
||||
# Solving N+1 Problem
|
||||
Since: 0.9.0
|
||||
|
||||
|
||||
+15
-9
@@ -17,7 +17,9 @@ By default, each error entry is converted to an associative array with following
|
||||
<?php
|
||||
[
|
||||
'message' => 'Error message',
|
||||
'category' => 'graphql',
|
||||
'extensions' => [
|
||||
'category' => 'graphql'
|
||||
],
|
||||
'locations' => [
|
||||
['line' => 1, 'column' => 2]
|
||||
],
|
||||
@@ -67,7 +69,9 @@ When such exception is thrown it will be reported with a full error message:
|
||||
<?php
|
||||
[
|
||||
'message' => 'My reported error',
|
||||
'category' => 'businessLogic',
|
||||
'extensions' => [
|
||||
'category' => 'businessLogic'
|
||||
],
|
||||
'locations' => [
|
||||
['line' => 10, 'column' => 2]
|
||||
],
|
||||
@@ -86,12 +90,12 @@ GraphQL\Error\FormattedError::setInternalErrorMessage("Unexpected error");
|
||||
|
||||
# Debugging tools
|
||||
|
||||
During development or debugging use `$result->toArray(true)` to add **debugMessage** key to
|
||||
During development or debugging use `$result->toArray(DebugFlag::INCLUDE_DEBUG_MESSAGE)` to add **debugMessage** key to
|
||||
each formatted error entry. If you also want to add exception trace - pass flags instead:
|
||||
|
||||
```
|
||||
use GraphQL\Error\Debug;
|
||||
$debug = Debug::INCLUDE_DEBUG_MESSAGE | Debug::INCLUDE_TRACE;
|
||||
```php
|
||||
use GraphQL\Error\DebugFlag;
|
||||
$debug = DebugFlag::INCLUDE_DEBUG_MESSAGE | DebugFlag::INCLUDE_TRACE;
|
||||
$result = GraphQL::executeQuery(/*args*/)->toArray($debug);
|
||||
```
|
||||
|
||||
@@ -101,7 +105,9 @@ This will make each error entry to look like this:
|
||||
[
|
||||
'debugMessage' => 'Actual exception message',
|
||||
'message' => 'Internal server error',
|
||||
'category' => 'internal',
|
||||
'extensions' => [
|
||||
'category' => 'internal'
|
||||
],
|
||||
'locations' => [
|
||||
['line' => 10, 'column' => 2]
|
||||
],
|
||||
@@ -120,8 +126,8 @@ If you prefer the first resolver exception to be re-thrown, use following flags:
|
||||
```php
|
||||
<?php
|
||||
use GraphQL\GraphQL;
|
||||
use GraphQL\Error\Debug;
|
||||
$debug = Debug::INCLUDE_DEBUG_MESSAGE | Debug::RETHROW_INTERNAL_EXCEPTIONS;
|
||||
use GraphQL\Error\DebugFlag;
|
||||
$debug = DebugFlag::INCLUDE_DEBUG_MESSAGE | DebugFlag::RETHROW_INTERNAL_EXCEPTIONS;
|
||||
|
||||
// Following will throw if there was an exception in resolver during execution:
|
||||
$result = GraphQL::executeQuery(/*args*/)->toArray($debug);
|
||||
|
||||
+5
-5
@@ -66,11 +66,11 @@ Server also supports [PSR-7 request/response interfaces](http://www.php-fig.org/
|
||||
<?php
|
||||
use GraphQL\Server\StandardServer;
|
||||
use GraphQL\Executor\ExecutionResult;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
|
||||
/** @var ServerRequestInterface $psrRequest */
|
||||
/** @var RequestInterface $psrRequest */
|
||||
/** @var ResponseInterface $psrResponse */
|
||||
/** @var StreamInterface $psrBodyStream */
|
||||
$server = new StandardServer([/* server options, see below */]);
|
||||
@@ -86,9 +86,9 @@ $psrResponse = new SomePsr7ResponseImplementation(json_encode($result));
|
||||
|
||||
PSR-7 is useful when you want to integrate the server into existing framework:
|
||||
|
||||
- [PSR-7 for Laravel](https://laravel.com/docs/5.1/requests#psr7-requests)
|
||||
- [PSR-7 for Laravel](https://laravel.com/docs/requests#psr7-requests)
|
||||
- [Symfony PSR-7 Bridge](https://symfony.com/doc/current/components/psr7.html)
|
||||
- [Slim](https://www.slimframework.com/docs/concepts/value-objects.html)
|
||||
- [Slim](https://www.slimframework.com/docs/v4/concepts/value-objects.html)
|
||||
- [Zend Expressive](http://zendframework.github.io/zend-expressive/)
|
||||
|
||||
## Server configuration options
|
||||
@@ -120,7 +120,7 @@ use GraphQL\Server\StandardServer;
|
||||
$config = ServerConfig::create()
|
||||
->setSchema($schema)
|
||||
->setErrorFormatter($myFormatter)
|
||||
->setDebug($debug)
|
||||
->setDebugFlag($debug)
|
||||
;
|
||||
|
||||
$server = new StandardServer($config);
|
||||
|
||||
+2
-2
@@ -54,8 +54,8 @@ $queryType = new ObjectType([
|
||||
'args' => [
|
||||
'message' => Type::nonNull(Type::string()),
|
||||
],
|
||||
'resolve' => function ($root, $args) {
|
||||
return $root['prefix'] . $args['message'];
|
||||
'resolve' => function ($rootValue, $args) {
|
||||
return $rootValue['prefix'] . $args['message'];
|
||||
}
|
||||
],
|
||||
],
|
||||
|
||||
+146
-150
@@ -20,9 +20,11 @@ See [related documentation](executing-queries.md).
|
||||
* rootValue:
|
||||
* The value provided as the first argument to resolver functions on the top
|
||||
* level type (e.g. the query object type).
|
||||
* context:
|
||||
* The value provided as the third argument to all resolvers.
|
||||
* Use this to pass current session, user data, etc
|
||||
* contextValue:
|
||||
* The context value is provided as an argument to resolver functions after
|
||||
* field arguments. It is used to pass shared information useful at any point
|
||||
* during executing this query, for example the currently logged in user and
|
||||
* connections to databases or other services.
|
||||
* variableValues:
|
||||
* A mapping of variable name to runtime value to use for all variables
|
||||
* defined in the requestString.
|
||||
@@ -41,7 +43,7 @@ See [related documentation](executing-queries.md).
|
||||
*
|
||||
* @param string|DocumentNode $source
|
||||
* @param mixed $rootValue
|
||||
* @param mixed $context
|
||||
* @param mixed $contextValue
|
||||
* @param mixed[]|null $variableValues
|
||||
* @param ValidationRule[] $validationRules
|
||||
*
|
||||
@@ -51,12 +53,12 @@ static function executeQuery(
|
||||
GraphQL\Type\Schema $schema,
|
||||
$source,
|
||||
$rootValue = null,
|
||||
$context = null,
|
||||
$contextValue = null,
|
||||
$variableValues = null,
|
||||
string $operationName = null,
|
||||
callable $fieldResolver = null,
|
||||
array $validationRules = null
|
||||
)
|
||||
): GraphQL\Executor\ExecutionResult
|
||||
```
|
||||
|
||||
```php
|
||||
@@ -82,7 +84,7 @@ static function promiseToExecute(
|
||||
string $operationName = null,
|
||||
callable $fieldResolver = null,
|
||||
array $validationRules = null
|
||||
)
|
||||
): GraphQL\Executor\Promise\Promise
|
||||
```
|
||||
|
||||
```php
|
||||
@@ -93,7 +95,7 @@ static function promiseToExecute(
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
static function getStandardDirectives()
|
||||
static function getStandardDirectives(): array
|
||||
```
|
||||
|
||||
```php
|
||||
@@ -104,7 +106,7 @@ static function getStandardDirectives()
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
static function getStandardTypes()
|
||||
static function getStandardTypes(): array
|
||||
```
|
||||
|
||||
```php
|
||||
@@ -112,7 +114,7 @@ static function getStandardTypes()
|
||||
* Replaces standard types with types from this list (matching by name)
|
||||
* Standard types not listed here remain untouched.
|
||||
*
|
||||
* @param Type[] $types
|
||||
* @param array<string, ScalarType> $types
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
@@ -127,7 +129,7 @@ static function overrideStandardTypes(array $types)
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
static function getStandardValidationRules()
|
||||
static function getStandardValidationRules(): array
|
||||
```
|
||||
|
||||
```php
|
||||
@@ -136,7 +138,7 @@ static function getStandardValidationRules()
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
static function setDefaultFieldResolver(callable $fn)
|
||||
static function setDefaultFieldResolver(callable $fn): void
|
||||
```
|
||||
# GraphQL\Type\Definition\Type
|
||||
Registry of standard GraphQL types
|
||||
@@ -145,157 +147,114 @@ and a base class for all other types.
|
||||
**Class Methods:**
|
||||
```php
|
||||
/**
|
||||
* @return IDType
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
static function id()
|
||||
static function id(): GraphQL\Type\Definition\ScalarType
|
||||
```
|
||||
|
||||
```php
|
||||
/**
|
||||
* @return StringType
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
static function string()
|
||||
static function string(): GraphQL\Type\Definition\ScalarType
|
||||
```
|
||||
|
||||
```php
|
||||
/**
|
||||
* @return BooleanType
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
static function boolean()
|
||||
static function boolean(): GraphQL\Type\Definition\ScalarType
|
||||
```
|
||||
|
||||
```php
|
||||
/**
|
||||
* @return IntType
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
static function int()
|
||||
static function int(): GraphQL\Type\Definition\ScalarType
|
||||
```
|
||||
|
||||
```php
|
||||
/**
|
||||
* @return FloatType
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
static function float()
|
||||
static function float(): GraphQL\Type\Definition\ScalarType
|
||||
```
|
||||
|
||||
```php
|
||||
/**
|
||||
* @param Type|ObjectType|InterfaceType|UnionType|ScalarType|InputObjectType|EnumType|ListOfType|NonNull $wrappedType
|
||||
*
|
||||
* @return ListOfType
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
static function listOf($wrappedType)
|
||||
static function listOf(GraphQL\Type\Definition\Type $wrappedType): GraphQL\Type\Definition\ListOfType
|
||||
```
|
||||
|
||||
```php
|
||||
/**
|
||||
* @param NullableType $wrappedType
|
||||
*
|
||||
* @return NonNull
|
||||
* @param callable|NullableType $wrappedType
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
static function nonNull($wrappedType)
|
||||
static function nonNull($wrappedType): GraphQL\Type\Definition\NonNull
|
||||
```
|
||||
|
||||
```php
|
||||
/**
|
||||
* @param Type $type
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
static function isInputType($type)
|
||||
static function isInputType($type): bool
|
||||
```
|
||||
|
||||
```php
|
||||
/**
|
||||
* @param Type $type
|
||||
*
|
||||
* @return ObjectType|InterfaceType|UnionType|ScalarType|InputObjectType|EnumType
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
static function getNamedType($type)
|
||||
static function getNamedType($type): GraphQL\Type\Definition\Type
|
||||
```
|
||||
|
||||
```php
|
||||
/**
|
||||
* @param Type $type
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
static function isOutputType($type)
|
||||
static function isOutputType($type): bool
|
||||
```
|
||||
|
||||
```php
|
||||
/**
|
||||
* @param Type $type
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
static function isLeafType($type)
|
||||
static function isLeafType($type): bool
|
||||
```
|
||||
|
||||
```php
|
||||
/**
|
||||
* @param Type $type
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
static function isCompositeType($type)
|
||||
static function isCompositeType($type): bool
|
||||
```
|
||||
|
||||
```php
|
||||
/**
|
||||
* @param Type $type
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
static function isAbstractType($type)
|
||||
static function isAbstractType($type): bool
|
||||
```
|
||||
|
||||
```php
|
||||
/**
|
||||
* @param Type $type
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
static function isType($type)
|
||||
```
|
||||
|
||||
```php
|
||||
/**
|
||||
* @param Type $type
|
||||
*
|
||||
* @return NullableType
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
static function getNullableType($type)
|
||||
static function getNullableType(GraphQL\Type\Definition\Type $type): GraphQL\Type\Definition\Type
|
||||
```
|
||||
# GraphQL\Type\Definition\ResolveInfo
|
||||
Structure containing information useful for field resolution process.
|
||||
@@ -304,6 +263,14 @@ Passed as 4th argument to every field resolver. See [docs on field resolving (da
|
||||
|
||||
**Class Props:**
|
||||
```php
|
||||
/**
|
||||
* The definition of the field being resolved.
|
||||
*
|
||||
* @api
|
||||
* @var FieldDefinition
|
||||
*/
|
||||
public $fieldDefinition;
|
||||
|
||||
/**
|
||||
* The name of the field being resolved.
|
||||
*
|
||||
@@ -312,6 +279,14 @@ Passed as 4th argument to every field resolver. See [docs on field resolving (da
|
||||
*/
|
||||
public $fieldName;
|
||||
|
||||
/**
|
||||
* Expected return type of the field being resolved.
|
||||
*
|
||||
* @api
|
||||
* @var Type
|
||||
*/
|
||||
public $returnType;
|
||||
|
||||
/**
|
||||
* AST of all nodes referencing this field in the query.
|
||||
*
|
||||
@@ -320,14 +295,6 @@ public $fieldName;
|
||||
*/
|
||||
public $fieldNodes;
|
||||
|
||||
/**
|
||||
* Expected return type of the field being resolved.
|
||||
*
|
||||
* @api
|
||||
* @var ScalarType|ObjectType|InterfaceType|UnionType|EnumType|ListOfType|NonNull
|
||||
*/
|
||||
public $returnType;
|
||||
|
||||
/**
|
||||
* Parent type of the field being resolved.
|
||||
*
|
||||
@@ -340,7 +307,7 @@ public $parentType;
|
||||
* Path to this field from the very root value.
|
||||
*
|
||||
* @api
|
||||
* @var string[][]
|
||||
* @var string[]
|
||||
*/
|
||||
public $path;
|
||||
|
||||
@@ -420,7 +387,7 @@ public $variableValues;
|
||||
*
|
||||
* @param int $depth How many levels to include in output
|
||||
*
|
||||
* @return bool[]
|
||||
* @return array<string, mixed>
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
@@ -438,6 +405,7 @@ const FIELD = "FIELD";
|
||||
const FRAGMENT_DEFINITION = "FRAGMENT_DEFINITION";
|
||||
const FRAGMENT_SPREAD = "FRAGMENT_SPREAD";
|
||||
const INLINE_FRAGMENT = "INLINE_FRAGMENT";
|
||||
const VARIABLE_DEFINITION = "VARIABLE_DEFINITION";
|
||||
const SCHEMA = "SCHEMA";
|
||||
const SCALAR = "SCALAR";
|
||||
const OBJECT = "OBJECT";
|
||||
@@ -481,7 +449,7 @@ static function create(array $options = [])
|
||||
|
||||
```php
|
||||
/**
|
||||
* @return ObjectType
|
||||
* @return ObjectType|null
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
@@ -490,7 +458,7 @@ function getQuery()
|
||||
|
||||
```php
|
||||
/**
|
||||
* @param ObjectType $query
|
||||
* @param ObjectType|null $query
|
||||
*
|
||||
* @return SchemaConfig
|
||||
*
|
||||
@@ -501,7 +469,7 @@ function setQuery($query)
|
||||
|
||||
```php
|
||||
/**
|
||||
* @return ObjectType
|
||||
* @return ObjectType|null
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
@@ -510,7 +478,7 @@ function getMutation()
|
||||
|
||||
```php
|
||||
/**
|
||||
* @param ObjectType $mutation
|
||||
* @param ObjectType|null $mutation
|
||||
*
|
||||
* @return SchemaConfig
|
||||
*
|
||||
@@ -521,7 +489,7 @@ function setMutation($mutation)
|
||||
|
||||
```php
|
||||
/**
|
||||
* @return ObjectType
|
||||
* @return ObjectType|null
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
@@ -530,7 +498,7 @@ function getSubscription()
|
||||
|
||||
```php
|
||||
/**
|
||||
* @param ObjectType $subscription
|
||||
* @param ObjectType|null $subscription
|
||||
*
|
||||
* @return SchemaConfig
|
||||
*
|
||||
@@ -541,7 +509,7 @@ function setSubscription($subscription)
|
||||
|
||||
```php
|
||||
/**
|
||||
* @return Type[]
|
||||
* @return Type[]|callable
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
@@ -561,7 +529,7 @@ function setTypes($types)
|
||||
|
||||
```php
|
||||
/**
|
||||
* @return Directive[]
|
||||
* @return Directive[]|null
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
@@ -581,7 +549,7 @@ function setDirectives(array $directives)
|
||||
|
||||
```php
|
||||
/**
|
||||
* @return callable
|
||||
* @return callable(string $name):Type|null
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
@@ -659,7 +627,7 @@ function getDirectives()
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
function getQueryType()
|
||||
function getQueryType(): GraphQL\Type\Definition\Type
|
||||
```
|
||||
|
||||
```php
|
||||
@@ -670,7 +638,7 @@ function getQueryType()
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
function getMutationType()
|
||||
function getMutationType(): GraphQL\Type\Definition\Type
|
||||
```
|
||||
|
||||
```php
|
||||
@@ -681,7 +649,7 @@ function getMutationType()
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
function getSubscriptionType()
|
||||
function getSubscriptionType(): GraphQL\Type\Definition\Type
|
||||
```
|
||||
|
||||
```php
|
||||
@@ -695,15 +663,11 @@ function getConfig()
|
||||
|
||||
```php
|
||||
/**
|
||||
* Returns type by it's name
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return Type|null
|
||||
* Returns type by its name
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
function getType($name)
|
||||
function getType(string $name): GraphQL\Type\Definition\Type
|
||||
```
|
||||
|
||||
```php
|
||||
@@ -713,11 +677,13 @@ function getType($name)
|
||||
*
|
||||
* This operation requires full schema scan. Do not use in production environment.
|
||||
*
|
||||
* @return ObjectType[]
|
||||
* @param InterfaceType|UnionType $abstractType
|
||||
*
|
||||
* @return array<Type&ObjectType>
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
function getPossibleTypes(GraphQL\Type\Definition\AbstractType $abstractType)
|
||||
function getPossibleTypes(GraphQL\Type\Definition\Type $abstractType): array
|
||||
```
|
||||
|
||||
```php
|
||||
@@ -725,27 +691,21 @@ function getPossibleTypes(GraphQL\Type\Definition\AbstractType $abstractType)
|
||||
* Returns true if object type is concrete type of given abstract type
|
||||
* (implementation for interfaces and members of union type for unions)
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
function isPossibleType(
|
||||
GraphQL\Type\Definition\AbstractType $abstractType,
|
||||
GraphQL\Type\Definition\ObjectType $possibleType
|
||||
)
|
||||
): bool
|
||||
```
|
||||
|
||||
```php
|
||||
/**
|
||||
* Returns instance of directive by name
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return Directive
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
function getDirective($name)
|
||||
function getDirective(string $name): GraphQL\Type\Definition\Directive
|
||||
```
|
||||
|
||||
```php
|
||||
@@ -776,6 +736,42 @@ function validate()
|
||||
# GraphQL\Language\Parser
|
||||
Parses string containing GraphQL query or [type definition](type-system/type-language.md) to Abstract Syntax Tree.
|
||||
|
||||
Those magic functions allow partial parsing:
|
||||
|
||||
@method static DocumentNode document(Source|string $source, bool[] $options = [])
|
||||
@method static ExecutableDefinitionNode executableDefinition(Source|string $source, bool[] $options = [])
|
||||
@method static string operationType(Source|string $source, bool[] $options = [])
|
||||
@method static VariableDefinitionNode variableDefinition(Source|string $source, bool[] $options = [])
|
||||
@method static SelectionSetNode selectionSet(Source|string $source, bool[] $options = [])
|
||||
@method static FieldNode field(Source|string $source, bool[] $options = [])
|
||||
@method static NodeList<ArgumentNode> constArguments(Source|string $source, bool[] $options = [])
|
||||
@method static ArgumentNode constArgument(Source|string $source, bool[] $options = [])
|
||||
@method static FragmentDefinitionNode fragmentDefinition(Source|string $source, bool[] $options = [])
|
||||
@method static BooleanValueNode|EnumValueNode|FloatValueNode|IntValueNode|ListValueNode|NullValueNode|ObjectValueNode|StringValueNode|VariableNode valueLiteral(Source|string $source, bool[] $options = [])
|
||||
@method static StringValueNode stringLiteral(Source|string $source, bool[] $options = [])
|
||||
@method static BooleanValueNode|EnumValueNode|FloatValueNode|IntValueNode|ListValueNode|ObjectValueNode|StringValueNode|VariableNode variableValue(Source|string $source, bool[] $options = [])
|
||||
@method static ListValueNode constArray(Source|string $source, bool[] $options = [])
|
||||
@method static ObjectValueNode constObject(Source|string $source, bool[] $options = [])
|
||||
@method static ObjectFieldNode constObjectField(Source|string $source, bool[] $options = [])
|
||||
@method static NodeList<DirectiveNode> constDirectives(Source|string $source, bool[] $options = [])
|
||||
@method static DirectiveNode constDirective(Source|string $source, bool[] $options = [])
|
||||
@method static NamedTypeNode namedType(Source|string $source, bool[] $options = [])
|
||||
@method static StringValueNode|null description(Source|string $source, bool[] $options = [])
|
||||
@method static OperationTypeDefinitionNode operationTypeDefinition(Source|string $source, bool[] $options = [])
|
||||
@method static ObjectTypeDefinitionNode objectTypeDefinition(Source|string $source, bool[] $options = [])
|
||||
@method static NodeList<FieldDefinitionNode> fieldsDefinition(Source|string $source, bool[] $options = [])
|
||||
@method static NodeList<InputValueDefinitionNode> argumentsDefinition(Source|string $source, bool[] $options = [])
|
||||
@method static InterfaceTypeDefinitionNode interfaceTypeDefinition(Source|string $source, bool[] $options = [])
|
||||
@method static NamedTypeNode[] unionMemberTypes(Source|string $source, bool[] $options = [])
|
||||
@method static NodeList<EnumValueDefinitionNode> enumValuesDefinition(Source|string $source, bool[] $options = [])
|
||||
@method static InputObjectTypeDefinitionNode inputObjectTypeDefinition(Source|string $source, bool[] $options = [])
|
||||
@method static TypeExtensionNode typeExtension(Source|string $source, bool[] $options = [])
|
||||
@method static ScalarTypeExtensionNode scalarTypeExtension(Source|string $source, bool[] $options = [])
|
||||
@method static InterfaceTypeExtensionNode interfaceTypeExtension(Source|string $source, bool[] $options = [])
|
||||
@method static EnumTypeExtensionNode enumTypeExtension(Source|string $source, bool[] $options = [])
|
||||
@method static DirectiveDefinitionNode directiveDefinition(Source|string $source, bool[] $options = [])
|
||||
@method static DirectiveLocation directiveLocation(Source|string $source, bool[] $options = [])
|
||||
|
||||
**Class Methods:**
|
||||
```php
|
||||
/**
|
||||
@@ -866,7 +862,7 @@ static function parseValue($source, array $options = [])
|
||||
* @param Source|string $source
|
||||
* @param bool[] $options
|
||||
*
|
||||
* @return ListTypeNode|NameNode|NonNullTypeNode
|
||||
* @return ListTypeNode|NamedTypeNode|NonNullTypeNode
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
@@ -1229,16 +1225,13 @@ function setErrorsHandler(callable $handler)
|
||||
* If debug argument is passed, output of error formatter is enriched which debugging information
|
||||
* ("debugMessage", "trace" keys depending on flags).
|
||||
*
|
||||
* $debug argument must be either bool (only adds "debugMessage" to result) or sum of flags from
|
||||
* GraphQL\Error\Debug
|
||||
*
|
||||
* @param bool|int $debug
|
||||
* $debug argument must sum of flags from @see \GraphQL\Error\DebugFlag
|
||||
*
|
||||
* @return mixed[]
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
function toArray($debug = false)
|
||||
function toArray(int $debug = "GraphQL\Error\DebugFlag::NONE"): array
|
||||
```
|
||||
# GraphQL\Executor\Promise\PromiseAdapter
|
||||
Provides a means for integration of async PHP platforms ([related docs](data-fetching.md#async-php))
|
||||
@@ -1487,7 +1480,7 @@ const ALL = 63;
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
static function setWarningHandler(callable $warningHandler = null)
|
||||
static function setWarningHandler(callable $warningHandler = null): void
|
||||
```
|
||||
|
||||
```php
|
||||
@@ -1503,7 +1496,7 @@ static function setWarningHandler(callable $warningHandler = null)
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
static function suppress($suppress = true)
|
||||
static function suppress($suppress = true): void
|
||||
```
|
||||
|
||||
```php
|
||||
@@ -1519,7 +1512,7 @@ static function suppress($suppress = true)
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
static function enable($enable = true)
|
||||
static function enable($enable = true): void
|
||||
```
|
||||
# GraphQL\Error\ClientAware
|
||||
This interface is used for [default error formatting](error-handling.md).
|
||||
@@ -1553,11 +1546,12 @@ function isClientSafe()
|
||||
*/
|
||||
function getCategory()
|
||||
```
|
||||
# GraphQL\Error\Debug
|
||||
# GraphQL\Error\DebugFlag
|
||||
Collection of flags for [error debugging](error-handling.md#debugging-tools).
|
||||
|
||||
**Class Constants:**
|
||||
```php
|
||||
const NONE = 0;
|
||||
const INCLUDE_DEBUG_MESSAGE = 1;
|
||||
const INCLUDE_TRACE = 2;
|
||||
const RETHROW_INTERNAL_EXCEPTIONS = 4;
|
||||
@@ -1590,11 +1584,9 @@ static function setInternalErrorMessage($msg)
|
||||
* This method only exposes exception message when exception implements ClientAware interface
|
||||
* (or when debug flags are passed).
|
||||
*
|
||||
* For a list of available debug flags see GraphQL\Error\Debug constants.
|
||||
* For a list of available debug flags @see \GraphQL\Error\DebugFlag constants.
|
||||
*
|
||||
* @param Throwable $e
|
||||
* @param bool|int $debug
|
||||
* @param string $internalErrorMessage
|
||||
* @param string $internalErrorMessage
|
||||
*
|
||||
* @return mixed[]
|
||||
*
|
||||
@@ -1602,7 +1594,11 @@ static function setInternalErrorMessage($msg)
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
static function createFromException($e, $debug = false, $internalErrorMessage = null)
|
||||
static function createFromException(
|
||||
Throwable $exception,
|
||||
int $debug = "GraphQL\Error\DebugFlag::NONE",
|
||||
$internalErrorMessage = null
|
||||
): array
|
||||
```
|
||||
|
||||
```php
|
||||
@@ -1718,7 +1714,7 @@ function executeRequest($parsedBody = null)
|
||||
* @api
|
||||
*/
|
||||
function processPsrRequest(
|
||||
Psr\Http\Message\ServerRequestInterface $request,
|
||||
Psr\Http\Message\RequestInterface $request,
|
||||
Psr\Http\Message\ResponseInterface $response,
|
||||
Psr\Http\Message\StreamInterface $writableBodyStream
|
||||
)
|
||||
@@ -1733,7 +1729,7 @@ function processPsrRequest(
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
function executePsrRequest(Psr\Http\Message\ServerRequestInterface $request)
|
||||
function executePsrRequest(Psr\Http\Message\RequestInterface $request)
|
||||
```
|
||||
|
||||
```php
|
||||
@@ -1832,7 +1828,7 @@ function setErrorsHandler(callable $handler)
|
||||
/**
|
||||
* Set validation rules for this server.
|
||||
*
|
||||
* @param ValidationRule[]|callable $validationRules
|
||||
* @param ValidationRule[]|callable|null $validationRules
|
||||
*
|
||||
* @return self
|
||||
*
|
||||
@@ -1865,15 +1861,11 @@ function setPersistentQueryLoader(callable $persistentQueryLoader)
|
||||
|
||||
```php
|
||||
/**
|
||||
* Set response debug flags. See GraphQL\Error\Debug class for a list of all available flags
|
||||
*
|
||||
* @param bool|int $set
|
||||
*
|
||||
* @return self
|
||||
* Set response debug flags. @see \GraphQL\Error\DebugFlag class for a list of all available flags
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
function setDebug($set = true)
|
||||
function setDebugFlag(int $debugFlag = "GraphQL\Error\DebugFlag::INCLUDE_DEBUG_MESSAGE"): self
|
||||
```
|
||||
|
||||
```php
|
||||
@@ -1882,7 +1874,7 @@ function setDebug($set = true)
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
function setQueryBatching(bool $enableBatching)
|
||||
function setQueryBatching(bool $enableBatching): self
|
||||
```
|
||||
|
||||
```php
|
||||
@@ -1947,7 +1939,7 @@ function parseRequestParams($method, array $bodyParams, array $queryParams)
|
||||
* Checks validity of OperationParams extracted from HTTP request and returns an array of errors
|
||||
* if params are invalid (or empty array when params are valid)
|
||||
*
|
||||
* @return Error[]
|
||||
* @return array<int, RequestError>
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
@@ -2002,7 +1994,7 @@ function sendResponse($result, $exitWhenDone = false)
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
function parsePsrRequest(Psr\Http\Message\ServerRequestInterface $request)
|
||||
function parsePsrRequest(Psr\Http\Message\RequestInterface $request)
|
||||
```
|
||||
|
||||
```php
|
||||
@@ -2073,7 +2065,7 @@ public $extensions;
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
static function create(array $params, bool $readonly = false)
|
||||
static function create(array $params, bool $readonly = false): GraphQL\Server\OperationParams
|
||||
```
|
||||
|
||||
```php
|
||||
@@ -2133,6 +2125,7 @@ static function build($source, callable $typeConfigDecorator = null, array $opti
|
||||
*
|
||||
* - commentDescriptions:
|
||||
* Provide true to use preceding comments as the description.
|
||||
* This option is provided to ease adoption and will be removed in v16.
|
||||
*
|
||||
* @param bool[] $options
|
||||
*
|
||||
@@ -2178,7 +2171,7 @@ Various utilities dealing with AST
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
static function fromArray(array $node)
|
||||
static function fromArray(array $node): GraphQL\Language\AST\Node
|
||||
```
|
||||
|
||||
```php
|
||||
@@ -2189,7 +2182,7 @@ static function fromArray(array $node)
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
static function toArray(GraphQL\Language\AST\Node $node)
|
||||
static function toArray(GraphQL\Language\AST\Node $node): array
|
||||
```
|
||||
|
||||
```php
|
||||
@@ -2213,7 +2206,7 @@ static function toArray(GraphQL\Language\AST\Node $node)
|
||||
*
|
||||
* @param Type|mixed|null $value
|
||||
*
|
||||
* @return ObjectValueNode|ListValueNode|BooleanValueNode|IntValueNode|FloatValueNode|EnumValueNode|StringValueNode|NullValueNode
|
||||
* @return ObjectValueNode|ListValueNode|BooleanValueNode|IntValueNode|FloatValueNode|EnumValueNode|StringValueNode|NullValueNode|null
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
@@ -2240,8 +2233,8 @@ static function astFromValue($value, GraphQL\Type\Definition\InputType $type)
|
||||
* | Enum Value | Mixed |
|
||||
* | Null Value | null |
|
||||
*
|
||||
* @param ValueNode|null $valueNode
|
||||
* @param mixed[]|null $variables
|
||||
* @param VariableNode|NullValueNode|IntValueNode|FloatValueNode|StringValueNode|BooleanValueNode|EnumValueNode|ListValueNode|ObjectValueNode|null $valueNode
|
||||
* @param mixed[]|null $variables
|
||||
*
|
||||
* @return mixed[]|stdClass|null
|
||||
*
|
||||
@@ -2249,7 +2242,11 @@ static function astFromValue($value, GraphQL\Type\Definition\InputType $type)
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
static function valueFromAST($valueNode, GraphQL\Type\Definition\InputType $type, array $variables = null)
|
||||
static function valueFromAST(
|
||||
GraphQL\Language\AST\ValueNode $valueNode,
|
||||
GraphQL\Type\Definition\Type $type,
|
||||
array $variables = null
|
||||
)
|
||||
```
|
||||
|
||||
```php
|
||||
@@ -2302,7 +2299,7 @@ static function typeFromAST(GraphQL\Type\Schema $schema, $inputTypeNode)
|
||||
*
|
||||
* @param string $operationName
|
||||
*
|
||||
* @return bool
|
||||
* @return bool|string
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
@@ -2314,23 +2311,22 @@ Given an instance of Schema, prints it in GraphQL type language.
|
||||
**Class Methods:**
|
||||
```php
|
||||
/**
|
||||
* Accepts options as a second argument:
|
||||
*
|
||||
* @param array<string, bool> $options
|
||||
* Available options:
|
||||
* - commentDescriptions:
|
||||
* Provide true to use preceding comments as the description.
|
||||
*
|
||||
* @param bool[] $options
|
||||
* This option is provided to ease adoption and will be removed in v16.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
static function doPrint(GraphQL\Type\Schema $schema, array $options = [])
|
||||
static function doPrint(GraphQL\Type\Schema $schema, array $options = []): string
|
||||
```
|
||||
|
||||
```php
|
||||
/**
|
||||
* @param bool[] $options
|
||||
* @param array<string, bool> $options
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
static function printIntrospectionSchema(GraphQL\Type\Schema $schema, array $options = [])
|
||||
static function printIntrospectionSchema(GraphQL\Type\Schema $schema, array $options = []): string
|
||||
```
|
||||
|
||||
@@ -158,7 +158,7 @@ $heroType = new ObjectType([
|
||||
'args' => [
|
||||
'episode' => Type::nonNull($enumType)
|
||||
],
|
||||
'resolve' => function($_value, $args) {
|
||||
'resolve' => function($hero, $args) {
|
||||
return $args['episode'] === 5 ? true : false;
|
||||
}
|
||||
]
|
||||
|
||||
@@ -131,7 +131,7 @@ $queryType = new ObjectType([
|
||||
'type' => Type::listOf($storyType),
|
||||
'args' => [
|
||||
'filters' => [
|
||||
'type' => Type::nonNull($filters),
|
||||
'type' => $filters,
|
||||
'defaultValue' => [
|
||||
'popular' => true
|
||||
]
|
||||
|
||||
@@ -134,3 +134,41 @@ concrete Object Type.
|
||||
If a **resolveType** option is omitted, graphql-php will loop through all interface implementors and
|
||||
use their **isTypeOf** callback to pick the first suitable one. This is obviously less efficient
|
||||
than single **resolveType** call. So it is recommended to define **resolveType** whenever possible.
|
||||
|
||||
# Prevent invisible types
|
||||
When object types that implement an interface are not directly referenced by a field, they cannot
|
||||
be discovered during schema introspection. For example:
|
||||
|
||||
```graphql
|
||||
type Query {
|
||||
animal: Animal
|
||||
}
|
||||
|
||||
interface Animal {...}
|
||||
|
||||
type Cat implements Animal {...}
|
||||
type Dog implements Animal {...}
|
||||
```
|
||||
|
||||
In this example, `Cat` and `Dog` would be considered *invisible* types. Querying the `animal` field
|
||||
would fail, since no possible implementing types for `Animal` can be found.
|
||||
|
||||
There are two possible solutions:
|
||||
|
||||
1. Add fields that reference the invisible types directly, e.g.:
|
||||
|
||||
```graphql
|
||||
type Query {
|
||||
dog: Dog
|
||||
cat: Cat
|
||||
}
|
||||
```
|
||||
|
||||
2. Pass the invisible types during schema construction, e.g.:
|
||||
|
||||
```php
|
||||
new GraphQLSchema([
|
||||
'query' => ...,
|
||||
'types' => [$cat, $dog]
|
||||
]);
|
||||
```
|
||||
|
||||
@@ -80,7 +80,7 @@ Option | Type | Notes
|
||||
name | `string` | **Required.** Name of the field. When not set - inferred from **fields** array key (read about [shorthand field definition](#shorthand-field-definitions) below)
|
||||
type | `Type` | **Required.** An instance of internal or custom type. Note: type must be represented by a single instance within one schema (see also [Type Registry](index.md#type-registry))
|
||||
args | `array` | An array of possible type arguments. Each entry is expected to be an array with keys: **name**, **type**, **description**, **defaultValue**. See [Field Arguments](#field-arguments) section below.
|
||||
resolve | `callable` | **function($value, $args, $context, [ResolveInfo](../reference.md#graphqltypedefinitionresolveinfo) $info)**<br> Given the **$value** of this type, it is expected to return actual value of the current field. See section on [Data Fetching](../data-fetching.md) for details
|
||||
resolve | `callable` | **function($objectValue, $args, $context, [ResolveInfo](../reference.md#graphqltypedefinitionresolveinfo) $info)**<br> Given the **$objectValue** of this type, it is expected to return actual value of the current field. See section on [Data Fetching](../data-fetching.md) for details
|
||||
complexity | `callable` | **function($childrenComplexity, $args)**<br> Used to restrict query complexity. The feature is disabled by default, read about [Security](../security.md#query-complexity-analysis) to use it.
|
||||
description | `string` | Plain-text description of this field for clients (e.g. used by [GraphiQL](https://github.com/graphql/graphiql) for auto-generated documentation)
|
||||
deprecationReason | `string` | Text describing why this field is deprecated. When not empty - field will not be returned by introspection queries (unless forced)
|
||||
|
||||
@@ -100,7 +100,7 @@ class EmailType extends ScalarType
|
||||
* @return string
|
||||
* @throws Error
|
||||
*/
|
||||
public function parseLiteral($valueNode, array $variables = null)
|
||||
public function parseLiteral(Node $valueNode, ?array $variables = null)
|
||||
{
|
||||
// Note: throwing GraphQL\Error\Error vs \UnexpectedValueException to benefit from GraphQL
|
||||
// error location in query:
|
||||
|
||||
+1
-1
@@ -62,7 +62,7 @@ $mutationType = new ObjectType([
|
||||
'episode' => $episodeEnum,
|
||||
'review' => $reviewInputObject
|
||||
],
|
||||
'resolve' => function($val, $args) {
|
||||
'resolve' => function($rootValue, $args) {
|
||||
// TODOC
|
||||
}
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user