Type Registry
+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.
Technically you can create several instances of your type (for example for tests), but GraphQL\Type\Schema
diff --git a/complementary-tools/index.html b/complementary-tools/index.html
index 17a9209..3c07158 100755
--- a/complementary-tools/index.html
+++ b/complementary-tools/index.html
@@ -209,6 +209,7 @@
If you prefer first resolver exception to be re-thrown, use following flags:
+If you prefer the first resolver exception to be re-thrown, use following flags:
<?php
use GraphQL\GraphQL;
use GraphQL\Error\Debug;
@@ -306,6 +306,8 @@ $debug = Debug::INCLUDE_DEBUG_MESSAGE | Debug::RETHROW_INTERNAL_EXCEPTIONS;
$result = GraphQL::executeQuery(/*args*/)->toArray($debug);
+If you only want to re-throw Exceptions that are not marked as safe through the ClientAware
interface, use
+the flag Debug::RETHROW_UNSAFE_EXCEPTIONS
.
Custom Error Handling and Formatting
It is possible to define custom formatter and handler for result errors.
Formatter is responsible for converting instances of GraphQL\Error\Error
diff --git a/getting-started/index.html b/getting-started/index.html
index 316853f..d07ecf3 100755
--- a/getting-started/index.html
+++ b/getting-started/index.html
@@ -201,7 +201,7 @@
This documentation assumes your familiarity with GraphQL concepts. If it is not the case - first learn about GraphQL on the official website.
Installation
-Using composer, simply run:
+Using composer, run:
composer require webonyx/graphql-php
diff --git a/index.html b/index.html
index 8d6e0a0..24ef7df 100755
--- a/index.html
+++ b/index.html
@@ -283,5 +283,5 @@ as well as some experimental features like
diff --git a/reference/index.html b/reference/index.html
index f61ec8f..f0ec465 100755
--- a/reference/index.html
+++ b/reference/index.html
@@ -296,17 +296,13 @@ See related documentation.
* Empty array would allow to skip query validation (may be convenient for persisted
* queries which are validated before persisting and assumed valid during execution)
*
- * @api
- * @param \GraphQL\Type\Schema $schema
* @param string|DocumentNode $source
- * @param mixed $rootValue
- * @param mixed $context
- * @param array|null $variableValues
- * @param string|null $operationName
- * @param callable $fieldResolver
- * @param array $validationRules
+ * @param mixed $rootValue
+ * @param mixed $context
+ * @param mixed[]|null $variableValues
+ * @param ValidationRule[] $validationRules
*
- * @return ExecutionResult
+ * @api
*/
static function executeQuery(
GraphQL\Type\Schema $schema,
@@ -314,7 +310,7 @@ static function executeQuery(
$rootValue = null,
$context = null,
$variableValues = null,
- $operationName = null,
+ string $operationName = null,
callable $fieldResolver = null,
array $validationRules = null
)
@@ -324,18 +320,13 @@ static function executeQuery(
* Same as executeQuery(), but requires PromiseAdapter and always returns a Promise.
* Useful for Async PHP platforms.
*
- * @api
- * @param PromiseAdapter $promiseAdapter
- * @param \GraphQL\Type\Schema $schema
- * @param string|DocumentNode $source
- * @param mixed $rootValue
- * @param mixed $context
- * @param array|null $variableValues
- * @param string|null $operationName
- * @param callable $fieldResolver
- * @param array $validationRules
+ * @param string|DocumentNode $source
+ * @param mixed $rootValue
+ * @param mixed $context
+ * @param mixed[]|null $variableValues
+ * @param ValidationRule[]|null $validationRules
*
- * @return Promise
+ * @api
*/
static function promiseToExecute(
GraphQL\Executor\Promise\PromiseAdapter $promiseAdapter,
@@ -344,7 +335,7 @@ static function promiseToExecute(
$rootValue = null,
$context = null,
$variableValues = null,
- $operationName = null,
+ string $operationName = null,
callable $fieldResolver = null,
array $validationRules = null
)
@@ -353,8 +344,9 @@ static function promiseToExecute(
/**
* Returns directives defined in GraphQL spec
*
- * @api
* @return Directive[]
+ *
+ * @api
*/
static function getStandardDirectives()
@@ -362,140 +354,186 @@ static function getStandardDirectives()
/**
* Returns types defined in GraphQL spec
*
- * @api
* @return Type[]
+ *
+ * @api
*/
static function getStandardTypes()
/**
- * Returns standard validation rules implementing GraphQL spec
+ * Replaces standard types with types from this list (matching by name)
+ * Standard types not listed here remain untouched.
+ *
+ * @param Type[] $types
+ *
+ * @api
+ */
+static function overrideStandardTypes(array $types)
+
+
+/**
+ * Returns standard validation rules implementing GraphQL spec
+ *
+ * @return ValidationRule[]
*
* @api
- * @return AbstractValidationRule[]
*/
static function getStandardValidationRules()
+/**
+ * Set default resolver implementation
+ *
+ * @api
+ */
+static function setDefaultFieldResolver(callable $fn)
+
+
GraphQL\Type\Definition\Type
Registry of standard GraphQL types and a base class for all other types.
Class Methods:
/**
- * @api
* @return IDType
+ *
+ * @api
*/
static function id()
/**
- * @api
* @return StringType
+ *
+ * @api
*/
static function string()
/**
- * @api
* @return BooleanType
+ *
+ * @api
*/
static function boolean()
/**
- * @api
* @return IntType
+ *
+ * @api
*/
static function int()
/**
- * @api
* @return FloatType
+ *
+ * @api
*/
static function float()
/**
- * @api
* @param Type|ObjectType|InterfaceType|UnionType|ScalarType|InputObjectType|EnumType|ListOfType|NonNull $wrappedType
+ *
* @return ListOfType
+ *
+ * @api
*/
static function listOf($wrappedType)
/**
- * @api
* @param ObjectType|InterfaceType|UnionType|ScalarType|InputObjectType|EnumType|ListOfType $wrappedType
+ *
* @return NonNull
+ *
+ * @api
*/
static function nonNull($wrappedType)
/**
- * @api
* @param Type $type
+ *
* @return bool
+ *
+ * @api
*/
static function isInputType($type)
/**
- * @api
* @param Type $type
+ *
+ * @return ObjectType|InterfaceType|UnionType|ScalarType|InputObjectType|EnumType
+ *
+ * @api
+ */
+static function getNamedType($type)
+
+
+/**
+ * @param Type $type
+ *
* @return bool
+ *
+ * @api
*/
static function isOutputType($type)
/**
- * @api
- * @param $type
+ * @param Type $type
+ *
* @return bool
+ *
+ * @api
*/
static function isLeafType($type)
/**
- * @api
* @param Type $type
+ *
* @return bool
+ *
+ * @api
*/
static function isCompositeType($type)
/**
- * @api
* @param Type $type
+ *
* @return bool
+ *
+ * @api
*/
static function isAbstractType($type)
/**
- * @api
* @param Type $type
+ *
* @return bool
+ *
+ * @api
*/
static function isType($type)
/**
- * @api
* @param Type $type
+ *
* @return ObjectType|InterfaceType|UnionType|ScalarType|InputObjectType|EnumType|ListOfType
+ *
+ * @api
*/
static function getNullableType($type)
-/**
- * @api
- * @param Type $type
- * @return ObjectType|InterfaceType|UnionType|ScalarType|InputObjectType|EnumType
- */
-static function getNamedType($type)
-
-
GraphQL\Type\Definition\ResolveInfo
Structure containing information useful for field resolution process. Passed as 3rd argument to every field resolver. See docs on field resolving (data fetching).
@@ -504,7 +542,7 @@ Passed as 3rd argument to every field resolver. See * The name of the field being resolved * * @api - * @var string + * @var string|null */ public $fieldName; @@ -512,7 +550,7 @@ public $fieldName; * AST of all nodes referencing this field in the query. * * @api - * @var FieldNode[] + * @var FieldNode[]|null */ public $fieldNodes; @@ -528,7 +566,7 @@ public $returnType; * Parent type of the field being resolved * * @api - * @var ObjectType + * @var ObjectType|null */ public $parentType; @@ -536,7 +574,7 @@ public $parentType; * Path to this field from the very root value * * @api - * @var array + * @var string[] */ public $path; @@ -544,7 +582,7 @@ public $path; * Instance of a schema used for execution * * @api - * @var Schema + * @var Schema|null */ public $schema; @@ -552,7 +590,7 @@ public $schema; * AST of all fragments defined in query * * @api - * @var FragmentDefinitionNode[] + * @var FragmentDefinitionNode[]|null */ public $fragments; @@ -560,7 +598,7 @@ public $fragments; * Root value passed to query execution * * @api - * @var mixed + * @var mixed|null */ public $rootValue; @@ -568,7 +606,7 @@ public $rootValue; * AST of operation definition node (query, mutation) * * @api - * @var OperationDefinitionNode + * @var OperationDefinitionNode|null */ public $operation; @@ -576,7 +614,7 @@ public $operation; * Array of variables passed to query execution * * @api - * @var array + * @var mixed[]|null */ public $variableValues; @@ -613,9 +651,11 @@ public $variableValues; * Warning: this method it is a naive implementation which does not take into account * conditional typed fragments. So use it with care for fields of interface and union types. * - * @api * @param int $depth How many levels to include in output - * @return array + * + * @return bool[] + * + * @api */ function getFieldSelection($depth = 0) @@ -659,103 +699,121 @@ $schema = new Schema($config); * Converts an array of options to instance of SchemaConfig * (or just returns empty config when array is not passed). * - * @api - * @param array $options + * @param mixed[] $options + * * @return SchemaConfig + * + * @api */ static function create(array $options = [])/**
- * @api
- * @param ObjectType $query
- * @return SchemaConfig
- */
-function setQuery($query)
-
-
-/**
- * @api
- * @param ObjectType $mutation
- * @return SchemaConfig
- */
-function setMutation($mutation)
-
-
-/**
- * @api
- * @param ObjectType $subscription
- * @return SchemaConfig
- */
-function setSubscription($subscription)
-
-
-/**
- * @api
- * @param Type[]|callable $types
- * @return SchemaConfig
- */
-function setTypes($types)
-
-
-/**
- * @api
- * @param Directive[] $directives
- * @return SchemaConfig
- */
-function setDirectives(array $directives)
-
-
-/**
- * @api
- * @param callable $typeLoader
- * @return SchemaConfig
- */
-function setTypeLoader(callable $typeLoader)
-
-
-/**
- * @api
* @return ObjectType
+ *
+ * @api
*/
function getQuery()
/**
+ * @param ObjectType $query
+ *
+ * @return SchemaConfig
+ *
* @api
+ */
+function setQuery($query)
+
+
+/**
* @return ObjectType
+ *
+ * @api
*/
function getMutation()
/**
+ * @param ObjectType $mutation
+ *
+ * @return SchemaConfig
+ *
* @api
+ */
+function setMutation($mutation)
+
+
+/**
* @return ObjectType
+ *
+ * @api
*/
function getSubscription()
/**
+ * @param ObjectType $subscription
+ *
+ * @return SchemaConfig
+ *
* @api
+ */
+function setSubscription($subscription)
+
+
+/**
* @return Type[]
+ *
+ * @api
*/
function getTypes()
/**
+ * @param Type[]|callable $types
+ *
+ * @return SchemaConfig
+ *
* @api
+ */
+function setTypes($types)
+
+
+/**
* @return Directive[]
+ *
+ * @api
*/
function getDirectives()
/**
+ * @param Directive[] $directives
+ *
+ * @return SchemaConfig
+ *
* @api
+ */
+function setDirectives(array $directives)
+
+
+/**
* @return callable
+ *
+ * @api
*/
function getTypeLoader()
+/**
+ * @return SchemaConfig
+ *
+ * @api
+ */
+function setTypeLoader(callable $typeLoader)
+
+
GraphQL\Type\Schema
Schema Definition (see related docs)
A Schema is created by supplying the root types of each type of operation: @@ -775,66 +833,82 @@ $schema = new GraphQL\Type\Schema($config);
Class Methods:
/**
- * Schema constructor.
+ * @param mixed[]|SchemaConfig $config
*
* @api
- * @param array|SchemaConfig $config
*/
function __construct($config)
-/**
- * Returns schema query type
- *
- * @api
- * @return ObjectType
- */
-function getQueryType()
-
-
-/**
- * Returns schema mutation type
- *
- * @api
- * @return ObjectType|null
- */
-function getMutationType()
-
-
-/**
- * Returns schema subscription
- *
- * @api
- * @return ObjectType|null
- */
-function getSubscriptionType()
-
-
-/**
- * @api
- * @return SchemaConfig
- */
-function getConfig()
-
-
/**
* Returns array of all types in this schema. Keys of this array represent type names, values are instances
* of corresponding type definitions
*
* This operation requires full schema scan. Do not use in production environment.
*
- * @api
* @return Type[]
+ *
+ * @api
*/
function getTypeMap()
/**
- * Returns type by it's name
+ * Returns a list of directives supported by this schema
+ *
+ * @return Directive[]
*
* @api
+ */
+function getDirectives()
+
+
+/**
+ * Returns schema query type
+ *
+ * @return ObjectType
+ *
+ * @api
+ */
+function getQueryType()
+
+
+/**
+ * Returns schema mutation type
+ *
+ * @return ObjectType|null
+ *
+ * @api
+ */
+function getMutationType()
+
+
+/**
+ * Returns schema subscription
+ *
+ * @return ObjectType|null
+ *
+ * @api
+ */
+function getSubscriptionType()
+
+
+/**
+ * @return SchemaConfig
+ *
+ * @api
+ */
+function getConfig()
+
+
+/**
+ * Returns type by it's name
+ *
* @param string $name
- * @return Type
+ *
+ * @return Type|null
+ *
+ * @api
*/
function getType($name)
@@ -845,9 +919,9 @@ function getType($name)
*
* This operation requires full schema scan. Do not use in production environment.
*
- * @api
- * @param AbstractType $abstractType
* @return ObjectType[]
+ *
+ * @api
*/
function getPossibleTypes(GraphQL\Type\Definition\AbstractType $abstractType)
@@ -856,10 +930,9 @@ 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)
*
- * @api
- * @param AbstractType $abstractType
- * @param ObjectType $possibleType
* @return bool
+ *
+ * @api
*/
function isPossibleType(
GraphQL\Type\Definition\AbstractType $abstractType,
@@ -867,21 +940,14 @@ function isPossibleType(
)
-/**
- * Returns a list of directives supported by this schema
- *
- * @api
- * @return Directive[]
- */
-function getDirectives()
-
-
/**
* Returns instance of directive by name
*
- * @api
- * @param $name
+ * @param string $name
+ *
* @return Directive
+ *
+ * @api
*/
function getDirective($name)
@@ -891,10 +957,11 @@ function getDirective($name)
*
* This operation requires full schema scan. Do not use in production environment.
*
+ * @throws InvariantViolation
+ *
* @api
- * @return InvariantViolation[]|Error[]
*/
-function validate()
+function assertValid()
/**
@@ -902,10 +969,11 @@ function validate()
*
* This operation requires full schema scan. Do not use in production environment.
*
+ * @return InvariantViolation[]|Error[]
+ *
* @api
- * @throws InvariantViolation
*/
-function assertValid()
+function validate()
GraphQL\Language\Parser
@@ -918,29 +986,48 @@ function assertValid() * Available options: * * noLocation: boolean, - * (By default, the parser creates AST nodes that know the location - * in the source that they correspond to. This configuration flag - * disables that behavior for performance or testing.) + * (By default, the parser creates AST nodes that know the location + * in the source that they correspond to. This configuration flag + * disables that behavior for performance or testing.) + * + * allowLegacySDLEmptyFields: boolean + * If enabled, the parser will parse empty fields sets in the Schema + * Definition Language. Otherwise, the parser will follow the current + * specification. + * + * This option is provided to ease adoption of the final SDL specification + * and will be removed in a future major release. + * + * allowLegacySDLImplementsInterfaces: boolean + * If enabled, the parser will parse implemented interfaces with no `&` + * character between each interface. Otherwise, the parser will follow the + * current specification. + * + * This option is provided to ease adoption of the final SDL specification + * and will be removed in a future major release. * * experimentalFragmentVariables: boolean, - * (If enabled, the parser will understand and parse variable definitions - * contained in a fragment definition. They'll be represented in the - * `variableDefinitions` field of the FragmentDefinitionNode. + * (If enabled, the parser will understand and parse variable definitions + * contained in a fragment definition. They'll be represented in the + * `variableDefinitions` field of the FragmentDefinitionNode. * - * The syntax is identical to normal, query-defined variables. For example: + * The syntax is identical to normal, query-defined variables. For example: * - * fragment A($var: Boolean = false) on T { - * ... - * } + * fragment A($var: Boolean = false) on T { + * ... + * } * - * Note: this feature is experimental and may change or be removed in the - * future.) + * Note: this feature is experimental and may change or be removed in the + * future.) + * + * @param Source|string $source + * @param bool[] $options + * + * @return DocumentNode + * + * @throws SyntaxError * * @api - * @param Source|string $source - * @param array $options - * @return DocumentNode - * @throws SyntaxError */ static function parse($source, array $options = []) @@ -955,10 +1042,12 @@ static function parse($source, array $options = []) * * Consider providing the results to the utility function: `GraphQL\Utils\AST::valueFromAST()`. * - * @api * @param Source|string $source - * @param array $options + * @param bool[] $options + * * @return BooleanValueNode|EnumValueNode|FloatValueNode|IntValueNode|ListValueNode|ObjectValueNode|StringValueNode|VariableNode + * + * @api */ static function parseValue($source, array $options = []) @@ -973,10 +1062,12 @@ static function parseValue($source, array $options = []) * * Consider providing the results to the utility function: `GraphQL\Utils\AST::typeFromAST()`. * - * @api * @param Source|string $source - * @param array $options + * @param bool[] $options + * * @return ListTypeNode|NameNode|NonNullTypeNode + * + * @api */ static function parseType($source, array $options = []) @@ -994,9 +1085,11 @@ $printed = GraphQL\Language\Printer::doPrint($ast);/**
* Prints AST to string. Capable of printing GraphQL queries and Type definition language.
*
- * @api
* @param Node $ast
+ *
* @return string
+ *
+ * @api
*/
static function doPrint($ast)
@@ -1083,12 +1176,15 @@ visitor API:
/**
* Visit the AST (see class description for details)
*
- * @api
- * @param Node $root
- * @param array $visitor
- * @param array $keyMap
+ * @param Node|ArrayObject|stdClass $root
+ * @param callable[] $visitor
+ * @param mixed[]|null $keyMap
+ *
* @return Node|mixed
- * @throws \Exception
+ *
+ * @throws Exception
+ *
+ * @api
*/
static function visit($root, $visitor, $keyMap = null)
@@ -1096,8 +1192,9 @@ static function visit($root, $visitor, $keyMap = null)
/**
* Returns marker for visitor break
*
- * @api
* @return VisitorOperation
+ *
+ * @api
*/
static function stop()
@@ -1105,8 +1202,9 @@ static function stop()
/**
* Returns marker for skipping current node
*
- * @api
* @return VisitorOperation
+ *
+ * @api
*/
static function skipNode()
@@ -1114,8 +1212,9 @@ static function skipNode()
/**
* Returns marker for removing a node
*
- * @api
* @return VisitorOperation
+ *
+ * @api
*/
static function removeNode()
@@ -1164,6 +1263,7 @@ const UNION_TYPE_EXTENSION = "UnionTypeExtension";
const ENUM_TYPE_EXTENSION = "EnumTypeExtension";
const INPUT_OBJECT_TYPE_EXTENSION = "InputObjectTypeExtension";
const DIRECTIVE_DEFINITION = "DirectiveDefinition";
+const SCHEMA_EXTENSION = "SchemaExtension";
GraphQL\Executor\Executor
@@ -1175,20 +1275,18 @@ const DIRECTIVE_DEFINITION = "DirectiveDefinition"; * Always returns ExecutionResult and never throws. All errors which occur during operation * execution are collected in `$result->errors`. * - * @api - * @param Schema $schema - * @param DocumentNode $ast - * @param $rootValue - * @param $contextValue - * @param array|\ArrayAccess $variableValues - * @param null $operationName - * @param callable $fieldResolver + * @param mixed|null $rootValue + * @param mixed[]|null $contextValue + * @param mixed[]|ArrayAccess|null $variableValues + * @param string|null $operationName * * @return ExecutionResult|Promise + * + * @api */ static function execute( GraphQL\Type\Schema $schema, - GraphQL\Language\AST\DocumentNode $ast, + GraphQL\Language\AST\DocumentNode $documentNode, $rootValue = null, $contextValue = null, $variableValues = null, @@ -1203,21 +1301,19 @@ static function execute( * * Useful for async PHP platforms. * - * @api - * @param PromiseAdapter $promiseAdapter - * @param Schema $schema - * @param DocumentNode $ast - * @param null $rootValue - * @param null $contextValue - * @param null $variableValues - * @param null $operationName - * @param callable|null $fieldResolver + * @param mixed[]|null $rootValue + * @param mixed[]|null $contextValue + * @param mixed[]|null $variableValues + * @param string|null $operationName + * * @return Promise + * + * @api */ static function promiseToExecute( GraphQL\Executor\Promise\PromiseAdapter $promiseAdapter, GraphQL\Type\Schema $schema, - GraphQL\Language\AST\DocumentNode $ast, + GraphQL\Language\AST\DocumentNode $documentNode, $rootValue = null, $contextValue = null, $variableValues = null, @@ -1237,7 +1333,7 @@ serializable array usingtoArray()
* Data collected from resolvers during query execution
*
* @api
- * @var array
+ * @var mixed[]
*/
public $data;
@@ -1248,7 +1344,7 @@ public $data;
* contain original exception.
*
* @api
- * @var \GraphQL\Error\Error[]
+ * @var Error[]
*/
public $errors;
@@ -1257,7 +1353,7 @@ public $errors;
* Conforms to
*
* @api
- * @var array
+ * @var mixed[]
*/
public $extensions;
@@ -1276,9 +1372,9 @@ public $extensions;
* // ... other keys
* );
*
+ * @return self
+ *
* @api
- * @param callable $errorFormatter
- * @return $this
*/
function setErrorFormatter(callable $errorFormatter)
@@ -1293,9 +1389,9 @@ function setErrorFormatter(callable $errorFormatter)
* return array_map($formatter, $errors);
* }
*
+ * @return self
+ *
* @api
- * @param callable $handler
- * @return $this
*/
function setErrorsHandler(callable $handler)
@@ -1310,9 +1406,11 @@ function setErrorsHandler(callable $handler)
* $debug argument must be either bool (only adds "debugMessage" to result) or sum of flags from
* GraphQL\Error\Debug
*
- * @api
* @param bool|int $debug
- * @return array
+ *
+ * @return mixed[]
+ *
+ * @api
*/
function toArray($debug = false)
@@ -1323,9 +1421,11 @@ function toArray($debug = false)
/**
* Return true if the value is a promise or a deferred of the underlying platform
*
- * @api
* @param mixed $value
+ *
* @return bool
+ *
+ * @api
*/
function isThenable($value)
@@ -1333,9 +1433,11 @@ function isThenable($value)
/**
* Converts thenable of the underlying platform into GraphQL\Executor\Promise\Promise instance
*
- * @api
* @param object $thenable
+ *
* @return Promise
+ *
+ * @api
*/
function convertThenable($thenable)
@@ -1344,12 +1446,9 @@ function convertThenable($thenable)
* Accepts our Promise wrapper, extracts adopted promise out of it and executes actual `then` logic described
* in Promises/A+ specs. Then returns new wrapped instance of GraphQL\Executor\Promise\Promise.
*
- * @api
- * @param Promise $promise
- * @param callable|null $onFulfilled
- * @param callable|null $onRejected
- *
* @return Promise
+ *
+ * @api
*/
function then(
GraphQL\Executor\Promise\Promise $promise,
@@ -1364,9 +1463,9 @@ function then(
* Expected resolver signature:
* function(callable $resolve, callable $reject)
*
- * @api
- * @param callable $resolver
* @return Promise
+ *
+ * @api
*/
function create(callable $resolver)
@@ -1374,9 +1473,11 @@ function create(callable $resolver)
/**
* Creates a fulfilled Promise for a value if the value is not a promise.
*
- * @api
* @param mixed $value
+ *
* @return Promise
+ *
+ * @api
*/
function createFulfilled($value = null)
@@ -1385,9 +1486,11 @@ function createFulfilled($value = null)
* Creates a rejected promise for a reason if the reason is not a promise. If
* the provided reason is a promise, then it is returned as-is.
*
- * @api
- * @param \Throwable $reason
+ * @param Throwable $reason
+ *
* @return Promise
+ *
+ * @api
*/
function createRejected($reason)
@@ -1396,9 +1499,11 @@ function createRejected($reason)
* Given an array of promises (or values), returns a promise that is fulfilled when all the
* items in the array are fulfilled.
*
- * @api
- * @param array $promisesOrValues Promises or values.
+ * @param Promise[]|mixed[] $promisesOrValues Promises or values.
+ *
* @return Promise
+ *
+ * @api
*/
function all(array $promisesOrValues)
@@ -1409,7 +1514,7 @@ function all(array $promisesOrValues)
an empty array if no errors were encountered and the document is valid.
A list of specific validation rules may be provided. If not provided, the default list of rules defined by the GraphQL specification will be used.
-Each validation rule is an instance of GraphQL\Validator\Rules\AbstractValidationRule +
Each validation rule is an instance of GraphQL\Validator\Rules\ValidationRule which returns a visitor (see the GraphQL\Language\Visitor API).
Visitor methods are expected to return an instance of GraphQL\Error\Error, or array of such instances when invalid.
@@ -1419,12 +1524,11 @@ will be created from the provided schema./**
* Primary method for query validation. See class description for details.
*
- * @api
- * @param Schema $schema
- * @param DocumentNode $ast
- * @param AbstractValidationRule[]|null $rules
- * @param TypeInfo|null $typeInfo
+ * @param ValidationRule[]|null $rules
+ *
* @return Error[]
+ *
+ * @api
*/
static function validate(
GraphQL\Type\Schema $schema,
@@ -1437,8 +1541,9 @@ static function validate(
/**
* Returns all global validation rules.
*
+ * @return ValidationRule[]
+ *
* @api
- * @return AbstractValidationRule[]
*/
static function allRules()
@@ -1449,9 +1554,11 @@ static function allRules()
*
* $rule = DocumentValidator::getRule(GraphQL\Validator\Rules\QueryComplexity::class);
*
- * @api
* @param string $name
- * @return AbstractValidationRule
+ *
+ * @return ValidationRule
+ *
+ * @api
*/
static function getRule($name)
@@ -1460,9 +1567,8 @@ static function getRule($name)
* Add rule to list of global validation rules
*
* @api
- * @param AbstractValidationRule $rule
*/
-static function addRule(GraphQL\Validator\Rules\AbstractValidationRule $rule)
+static function addRule(GraphQL\Validator\Rules\ValidationRule $rule)
GraphQL\Error\Error
@@ -1492,8 +1598,9 @@ const CATEGORY_INTERNAL = "internal"; * point out to field mentioned in multiple fragments. Errors during execution include a * single location, the field which produced the error. * - * @api * @return SourceLocation[] + * + * @api */ function getLocations() @@ -1502,8 +1609,9 @@ function getLocations() * Returns an array describing the path from the root value to the field which produced this error. * Only included for execution errors. * + * @return mixed[]|null + * * @api - * @return array|null */ function getPath() @@ -1527,7 +1635,6 @@ const ALL = 63; * When not set, trigger_error() is used to notify about warnings. * * @api - * @param callable|null $warningHandler */ static function setWarningHandler(callable $warningHandler = null) @@ -1540,8 +1647,9 @@ static function setWarningHandler(callable $warningHandler = null) * * When passing true - suppresses all warnings. * - * @api * @param bool|int $suppress + * + * @api */ static function suppress($suppress = true) @@ -1554,8 +1662,9 @@ static function suppress($suppress = true) * * When passing true - re-enables all warnings. * - * @api * @param bool|int $enable + * + * @api */ static function enable($enable = true) @@ -1569,8 +1678,9 @@ will be formatted with original error message./**
* Returns true when exception message is safe to be displayed to a client.
*
- * @api
* @return bool
+ *
+ * @api
*/
function isClientSafe()
@@ -1580,8 +1690,9 @@ function isClientSafe()
*
* Value "graphql" is reserved for errors produced by query parsing or validation, do not use it.
*
- * @api
* @return string
+ *
+ * @api
*/
function getCategory()
@@ -1592,6 +1703,7 @@ function getCategory()
const INCLUDE_DEBUG_MESSAGE = 1;
const INCLUDE_TRACE = 2;
const RETHROW_INTERNAL_EXCEPTIONS = 4;
+const RETHROW_UNSAFE_EXCEPTIONS = 8;
GraphQL\Error\FormattedError
@@ -1603,8 +1715,9 @@ and provides tools for error debugging. * Set default error message for internal errors formatted using createFormattedError(). * This value can be overridden by passing 3rd argument to `createFormattedError()`. * - * @api * @param string $msg + * + * @api */ static function setInternalErrorMessage($msg) @@ -1618,12 +1731,15 @@ static function setInternalErrorMessage($msg) * * For a list of available debug flags see GraphQL\Error\Debug constants. * + * @param Throwable $e + * @param bool|int $debug + * @param string $internalErrorMessage + * + * @return mixed[] + * + * @throws Throwable + * * @api - * @param \Throwable $e - * @param bool|int $debug - * @param string $internalErrorMessage - * @return array - * @throws \Throwable */ static function createFromException($e, $debug = false, $internalErrorMessage = null) @@ -1631,9 +1747,11 @@ static function createFromException($e, $debug = false, $internalErrorMessage =/**
* Returns error trace as serializable array
*
+ * @param Throwable $error
+ *
+ * @return mixed[]
+ *
* @api
- * @param \Throwable $error
- * @return array
*/
static function toSafeTrace($error)
@@ -1662,10 +1780,11 @@ $server->handleRequest();
* Useful when an exception is thrown somewhere outside of server execution context
* (e.g. during schema instantiation).
*
+ * @param Throwable $error
+ * @param bool $debug
+ * @param bool $exitWhenDone
+ *
* @api
- * @param \Throwable $error
- * @param bool $debug
- * @param bool $exitWhenDone
*/
static function send500Error($error, $debug = false, $exitWhenDone = false)
@@ -1673,8 +1792,9 @@ static function send500Error($error, $debug = false, $exitWhenDone = false)
/**
* Creates new instance of a standard GraphQL HTTP server
*
+ * @param ServerConfig|mixed[] $config
+ *
* @api
- * @param ServerConfig|array $config
*/
function __construct($config)
@@ -1689,9 +1809,10 @@ function __construct($config)
* See `executeRequest()` if you prefer to emit response yourself
* (e.g. using Response object of some framework)
*
- * @api
* @param OperationParams|OperationParams[] $parsedBody
- * @param bool $exitWhenDone
+ * @param bool $exitWhenDone
+ *
+ * @api
*/
function handleRequest($parsedBody = null, $exitWhenDone = false)
@@ -1706,10 +1827,13 @@ function handleRequest($parsedBody = null, $exitWhenDone = false)
*
* PSR-7 compatible method executePsrRequest() does exactly this.
*
- * @api
* @param OperationParams|OperationParams[] $parsedBody
+ *
* @return ExecutionResult|ExecutionResult[]|Promise
+ *
* @throws InvariantViolation
+ *
+ * @api
*/
function executeRequest($parsedBody = null)
@@ -1720,11 +1844,9 @@ function executeRequest($parsedBody = null)
* See `executePsrRequest()` if you prefer to create response yourself
* (e.g. using specific JsonResponse instance of some framework).
*
- * @api
- * @param ServerRequestInterface $request
- * @param ResponseInterface $response
- * @param StreamInterface $writableBodyStream
* @return ResponseInterface|Promise
+ *
+ * @api
*/
function processPsrRequest(
Psr\Http\Message\ServerRequestInterface $request,
@@ -1737,9 +1859,9 @@ function processPsrRequest(
* Executes GraphQL operation and returns execution result
* (or promise when promise adapter is different from SyncPromiseAdapter)
*
- * @api
- * @param ServerRequestInterface $request
* @return ExecutionResult|ExecutionResult[]|Promise
+ *
+ * @api
*/
function executePsrRequest(Psr\Http\Message\ServerRequestInterface $request)
@@ -1748,8 +1870,9 @@ function executePsrRequest(Psr\Http\Message\ServerRequestInterface $request)
* Returns an instance of Server helper, which contains most of the actual logic for
* parsing / validating / executing request (which could be re-used by other server implementations)
*
- * @api
* @return Helper
+ *
+ * @api
*/
function getHelper()
@@ -1770,33 +1893,39 @@ $server = new GraphQL\Server\StandardServer($config);
* Converts an array of options to instance of ServerConfig
* (or just returns empty config when array is not passed).
*
- * @api
- * @param array $config
+ * @param mixed[] $config
+ *
* @return ServerConfig
+ *
+ * @api
*/
static function create(array $config = [])
/**
+ * @return self
+ *
* @api
- * @param Schema $schema
- * @return $this
*/
function setSchema(GraphQL\Type\Schema $schema)
/**
+ * @param mixed|callable $context
+ *
+ * @return self
+ *
* @api
- * @param mixed|\Closure $context
- * @return $this
*/
function setContext($context)
/**
+ * @param mixed|callable $rootValue
+ *
+ * @return self
+ *
* @api
- * @param mixed|\Closure $rootValue
- * @return $this
*/
function setRootValue($rootValue)
@@ -1804,9 +1933,9 @@ function setRootValue($rootValue)
/**
* Expects function(Throwable $e) : array
*
+ * @return self
+ *
* @api
- * @param callable $errorFormatter
- * @return $this
*/
function setErrorFormatter(callable $errorFormatter)
@@ -1814,9 +1943,9 @@ function setErrorFormatter(callable $errorFormatter)
/**
* Expects function(array $errors, callable $formatter) : array
*
+ * @return self
+ *
* @api
- * @param callable $handler
- * @return $this
*/
function setErrorsHandler(callable $handler)
@@ -1824,17 +1953,19 @@ function setErrorsHandler(callable $handler)
/**
* Set validation rules for this server.
*
+ * @param ValidationRule[]|callable $validationRules
+ *
+ * @return self
+ *
* @api
- * @param array|callable
- * @return $this
*/
function setValidationRules($validationRules)
/**
+ * @return self
+ *
* @api
- * @param callable $fieldResolver
- * @return $this
*/
function setFieldResolver(callable $fieldResolver)
@@ -1844,9 +1975,9 @@ function setFieldResolver(callable $fieldResolver)
*
* This function must return query string or valid DocumentNode.
*
+ * @return self
+ *
* @api
- * @param callable $persistentQueryLoader
- * @return $this
*/
function setPersistentQueryLoader(callable $persistentQueryLoader)
@@ -1854,9 +1985,11 @@ function setPersistentQueryLoader(callable $persistentQueryLoader)
/**
* Set response debug flags. See GraphQL\Error\Debug class for a list of all available flags
*
- * @api
* @param bool|int $set
- * @return $this
+ *
+ * @return self
+ *
+ * @api
*/
function setDebug($set = true)
@@ -1864,17 +1997,19 @@ function setDebug($set = true)
/**
* Allow batching queries (disabled by default)
*
- * @api
* @param bool $enableBatching
- * @return $this
+ *
+ * @return self
+ *
+ * @api
*/
function setQueryBatching($enableBatching)
/**
+ * @return self
+ *
* @api
- * @param PromiseAdapter $promiseAdapter
- * @return $this
*/
function setPromiseAdapter(GraphQL\Executor\Promise\PromiseAdapter $promiseAdapter)
@@ -1897,10 +2032,11 @@ function setPromiseAdapter(GraphQL\Executor\Promise\PromiseAdapter $promiseAdapt
*
* For PSR-7 request parsing use `parsePsrRequest()` instead.
*
- * @api
- * @param callable|null $readRawBodyFn
* @return OperationParams|OperationParams[]
+ *
* @throws RequestError
+ *
+ * @api
*/
function parseHttpRequest(callable $readRawBodyFn = null)
@@ -1911,12 +2047,15 @@ function parseHttpRequest(callable $readRawBodyFn = null)
*
* Returned value is a suitable input for `executeOperation` or `executeBatch` (if array)
*
- * @api
- * @param string $method
- * @param array $bodyParams
- * @param array $queryParams
+ * @param string $method
+ * @param mixed[] $bodyParams
+ * @param mixed[] $queryParams
+ *
* @return OperationParams|OperationParams[]
+ *
* @throws RequestError
+ *
+ * @api
*/
function parseRequestParams($method, array $bodyParams, array $queryParams)
@@ -1925,9 +2064,9 @@ 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)
*
- * @api
- * @param OperationParams $params
* @return Error[]
+ *
+ * @api
*/
function validateOperationParams(GraphQL\Server\OperationParams $params)
@@ -1936,11 +2075,9 @@ function validateOperationParams(GraphQL\Server\OperationParams $params)
* Executes GraphQL operation with given server configuration and returns execution result
* (or promise when promise adapter is different from SyncPromiseAdapter)
*
- * @api
- * @param ServerConfig $config
- * @param OperationParams $op
- *
* @return ExecutionResult|Promise
+ *
+ * @api
*/
function executeOperation(GraphQL\Server\ServerConfig $config, GraphQL\Server\OperationParams $op)
@@ -1949,10 +2086,11 @@ function executeOperation(GraphQL\Server\ServerConfig $config, GraphQL\Server\Op
* Executes batched GraphQL operations with shared promise queue
* (thus, effectively batching deferreds|promises of all queries at once)
*
- * @api
- * @param ServerConfig $config
* @param OperationParams[] $operations
- * @return ExecutionResult[]|Promise
+ *
+ * @return ExecutionResult|ExecutionResult[]|Promise
+ *
+ * @api
*/
function executeBatch(GraphQL\Server\ServerConfig $config, array $operations)
@@ -1960,9 +2098,10 @@ function executeBatch(GraphQL\Server\ServerConfig $config, array $operations)
/**
* Send response using standard PHP `header()` and `echo`.
*
- * @api
* @param Promise|ExecutionResult|ExecutionResult[] $result
- * @param bool $exitWhenDone
+ * @param bool $exitWhenDone
+ *
+ * @api
*/
function sendResponse($result, $exitWhenDone = false)
@@ -1970,10 +2109,11 @@ function sendResponse($result, $exitWhenDone = false)
/**
* Converts PSR-7 request to OperationParams[]
*
- * @api
- * @param ServerRequestInterface $request
- * @return array|Helper
+ * @return OperationParams[]|OperationParams
+ *
* @throws RequestError
+ *
+ * @api
*/
function parsePsrRequest(Psr\Http\Message\ServerRequestInterface $request)
@@ -1981,11 +2121,11 @@ function parsePsrRequest(Psr\Http\Message\ServerRequestInterface $request)
/**
* Converts query execution result to PSR-7 response
*
- * @api
* @param Promise|ExecutionResult|ExecutionResult[] $result
- * @param ResponseInterface $response
- * @param StreamInterface $writableBodyStream
+ *
* @return Promise|ResponseInterface
+ *
+ * @api
*/
function toPsrResponse(
$result,
@@ -2024,7 +2164,7 @@ public $operation;
/**
* @api
- * @var array
+ * @var mixed[]|null
*/
public $variables;
@@ -2033,18 +2173,22 @@ public $variables;
/**
* Creates an instance from given array
*
- * @api
- * @param array $params
- * @param bool $readonly
+ * @param mixed[] $params
+ * @param bool $readonly
+ *
* @return OperationParams
+ *
+ * @api
*/
static function create(array $params, $readonly = false)
/**
- * @api
* @param string $key
+ *
* @return mixed
+ *
+ * @api
*/
function getOriginalInput($key)
@@ -2053,8 +2197,9 @@ function getOriginalInput($key)
* Indicates that operation is executed in read-only context
* (e.g. via HTTP GET request)
*
- * @api
* @return bool
+ *
+ * @api
*/
function isReadOnly()
@@ -2063,6 +2208,20 @@ function isReadOnly()
Build instance of GraphQL\Type\Schema
out of type language definition (string or parsed AST)
See section in docs for details.
Class Methods:
+/**
+ * A helper function to build a GraphQLSchema directly from a source
+ * document.
+ *
+ * @param DocumentNode|Source|string $source
+ * @param bool[] $options
+ *
+ * @return Schema
+ *
+ * @api
+ */
+static function build($source, callable $typeConfigDecorator = null, array $options = [])
+
+
/**
* This takes the ast of a schema document produced by the parse function in
* GraphQL\Language\Parser.
@@ -2073,31 +2232,24 @@ See section in docs for details.
* Given that AST it constructs a GraphQL\Type\Schema. The resulting schema
* has no resolve methods, so execution will use default resolvers.
*
- * Accepts options as a second argument:
+ * Accepts options as a third argument:
*
* - commentDescriptions:
* Provide true to use preceding comments as the description.
*
+ * @param bool[] $options
*
- * @api
- * @param DocumentNode $ast
- * @param array $options
* @return Schema
+ *
* @throws Error
- */
-static function buildAST(GraphQL\Language\AST\DocumentNode $ast, array $options = [])
-
-
-/**
- * A helper function to build a GraphQLSchema directly from a source
- * document.
*
* @api
- * @param DocumentNode|Source|string $source
- * @param array $options
- * @return Schema
*/
-static function build($source, array $options = [])
+static function buildAST(
+ GraphQL\Language\AST\DocumentNode $ast,
+ callable $typeConfigDecorator = null,
+ array $options = []
+)
GraphQL\Utils\AST
@@ -2124,9 +2276,9 @@ static function build($source, array $options = []) * * This is a reverse operation for AST::toArray($node) * + * @param mixed[] $node + * * @api - * @param array $node - * @return Node */ static function fromArray(array $node) @@ -2134,9 +2286,9 @@ static function fromArray(array $node)/**
* Convert AST node to serializable array
*
+ * @return mixed[]
+ *
* @api
- * @param Node $node
- * @return array
*/
static function toArray(GraphQL\Language\AST\Node $node)
@@ -2159,10 +2311,11 @@ static function toArray(GraphQL\Language\AST\Node $node)
* | Mixed | Enum Value |
* | null | NullValue |
*
- * @api
- * @param $value
- * @param InputType $type
+ * @param Type|mixed|null $value
+ *
* @return ObjectValueNode|ListValueNode|BooleanValueNode|IntValueNode|FloatValueNode|EnumValueNode|StringValueNode|NullValueNode
+ *
+ * @api
*/
static function astFromValue($value, GraphQL\Type\Definition\InputType $type)
@@ -2186,20 +2339,22 @@ static function astFromValue($value, GraphQL\Type\Definition\InputType $type)
* | Enum Value | Mixed |
* | Null Value | null |
*
+ * @param ValueNode|null $valueNode
+ * @param mixed[]|null $variables
+ *
+ * @return mixed[]|stdClass|null
+ *
+ * @throws Exception
+ *
* @api
- * @param $valueNode
- * @param InputType $type
- * @param null $variables
- * @return array|null|\stdClass
- * @throws \Exception
*/
-static function valueFromAST($valueNode, GraphQL\Type\Definition\InputType $type, $variables = null)
+static function valueFromAST($valueNode, GraphQL\Type\Definition\InputType $type, array $variables = null)
/**
* Produces a PHP value given a GraphQL Value AST.
*
- * Unlike `valueFromAST()`, no type is provided. The resulting JavaScript value
+ * Unlike `valueFromAST()`, no type is provided. The resulting PHP value
* will reflect the provided GraphQL value AST.
*
* | GraphQL Value | PHP Value |
@@ -2212,11 +2367,14 @@ static function valueFromAST($valueNode, GraphQL\Type\Definition\InputType $type
* | Enum | Mixed |
* | Null | null |
*
- * @api
- * @param Node $valueNode
- * @param array|null $variables
+ * @param Node $valueNode
+ * @param mixed[]|null $variables
+ *
* @return mixed
- * @throws \Exception
+ *
+ * @throws Exception
+ *
+ * @api
*/
static function valueFromASTUntyped($valueNode, array $variables = null)
@@ -2224,11 +2382,13 @@ static function valueFromASTUntyped($valueNode, array $variables = null)
/**
* Returns type definition for given AST Type node
*
- * @api
- * @param Schema $schema
* @param NamedTypeNode|ListTypeNode|NonNullTypeNode $inputTypeNode
- * @return Type
- * @throws \Exception
+ *
+ * @return Type|null
+ *
+ * @throws Exception
+ *
+ * @api
*/
static function typeFromAST(GraphQL\Type\Schema $schema, $inputTypeNode)
@@ -2236,10 +2396,11 @@ static function typeFromAST(GraphQL\Type\Schema $schema, $inputTypeNode)
/**
* Returns operation type ("query", "mutation" or "subscription") given a document and operation name
*
- * @api
- * @param DocumentNode $document
* @param string $operationName
+ *
* @return bool
+ *
+ * @api
*/
static function getOperation(GraphQL\Language\AST\DocumentNode $document, $operationName = null)
@@ -2252,19 +2413,20 @@ static function getOperation(GraphQL\Language\AST\DocumentNode $document, $opera
*
* - commentDescriptions:
* Provide true to use preceding comments as the description.
+ *
+ * @param bool[] $options
+ *
* @api
- * @param Schema $schema
- * @return string
*/
static function doPrint(GraphQL\Type\Schema $schema, array $options = [])
/**
+ * @param bool[] $options
+ *
* @api
- * @param Schema $schema
- * @return string
*/
-static function printIntrosepctionSchema(GraphQL\Type\Schema $schema, array $options = [])
+static function printIntrospectionSchema(GraphQL\Type\Schema $schema, array $options = [])