2017-08-20 19:28:59 +03:00
<!DOCTYPE html>
<!-- [if IE 8]><html class="no - js lt - ie9" lang="en" > <![endif] -->
<!-- [if gt IE 8]><! --> < html class = "no-js" lang = "en" > <!-- <![endif] -->
< head >
< meta charset = "utf-8" >
< meta http-equiv = "X-UA-Compatible" content = "IE=edge" >
< meta name = "viewport" content = "width=device-width, initial-scale=1.0" >
< link rel = "shortcut icon" href = "../img/favicon.ico" >
< title > Class Reference - graphql-php< / title >
< link href = 'https://fonts.googleapis.com/css?family=Lato:400,700|Roboto+Slab:400,700|Inconsolata:400,700' rel = 'stylesheet' type = 'text/css' >
< link rel = "stylesheet" href = "../css/theme.css" type = "text/css" / >
< link rel = "stylesheet" href = "../css/theme_extra.css" type = "text/css" / >
2018-11-27 16:06:49 +03:00
< link rel = "stylesheet" href = "//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css" >
2017-08-20 19:28:59 +03:00
< script >
// Current page data
var mkdocs_page_name = "Class Reference";
var mkdocs_page_input_path = "reference.md";
2018-11-27 16:06:49 +03:00
var mkdocs_page_url = null;
2017-08-20 19:28:59 +03:00
< / script >
2018-11-27 16:06:49 +03:00
< script src = "../js/jquery-2.1.1.min.js" defer > < / script >
< script src = "../js/modernizr-2.8.3.min.js" defer > < / script >
< script src = "//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js" > < / script >
< script > hljs . initHighlightingOnLoad ( ) ; < / script >
2017-08-20 19:28:59 +03:00
< / head >
< body class = "wy-body-for-nav" role = "document" >
< div class = "wy-grid-for-nav" >
< nav data-toggle = "wy-nav-shift" class = "wy-nav-side stickynav" >
< div class = "wy-side-nav-search" >
< a href = ".." class = "icon icon-home" > graphql-php< / a >
< div role = "search" >
< form id = "rtd-search-form" class = "wy-form" action = "../search.html" method = "get" >
2018-11-27 16:06:49 +03:00
< input type = "text" name = "q" placeholder = "Search docs" title = "Type search term here" / >
2017-08-20 19:28:59 +03:00
< / form >
< / div >
< / div >
< div class = "wy-menu wy-menu-vertical" data-spy = "affix" role = "navigation" aria-label = "main navigation" >
< ul class = "current" >
< li class = "toctree-l1" >
< a class = "" href = ".." > About< / a >
< / li >
< li class = "toctree-l1" >
< a class = "" href = "../getting-started/" > Getting Started< / a >
< / li >
< li class = "toctree-l1" >
< a class = "" href = "../complementary-tools/" > Complementary Tools< / a >
< / li >
< li class = "toctree-l1" >
< span class = "caption-text" > Type Definitions< / span >
< ul class = "subnav" >
< li class = "" >
< a class = "" href = "../type-system/" > Introduction< / a >
< / li >
< li class = "" >
< a class = "" href = "../type-system/object-types/" > Object Types< / a >
< / li >
< li class = "" >
< a class = "" href = "../type-system/scalar-types/" > Scalar Types< / a >
< / li >
< li class = "" >
< a class = "" href = "../type-system/enum-types/" > Enumeration Types< / a >
< / li >
< li class = "" >
< a class = "" href = "../type-system/lists-and-nonnulls/" > Lists and Non-Null< / a >
< / li >
< li class = "" >
< a class = "" href = "../type-system/interfaces/" > Interfaces< / a >
< / li >
< li class = "" >
< a class = "" href = "../type-system/unions/" > Unions< / a >
< / li >
< li class = "" >
< a class = "" href = "../type-system/input-types/" > Mutations and Input Types< / a >
< / li >
< li class = "" >
< a class = "" href = "../type-system/directives/" > Directives< / a >
< / li >
< li class = "" >
< a class = "" href = "../type-system/schema/" > Schema< / a >
< / li >
< li class = "" >
< a class = "" href = "../type-system/type-language/" > Using Type Language< / a >
< / li >
< / ul >
< / li >
< li class = "toctree-l1" >
< a class = "" href = "../executing-queries/" > Executing Queries< / a >
< / li >
< li class = "toctree-l1" >
< a class = "" href = "../data-fetching/" > Fetching Data< / a >
< / li >
< li class = "toctree-l1" >
< a class = "" href = "../error-handling/" > Handling Errors< / a >
< / li >
< li class = "toctree-l1" >
< a class = "" href = "../security/" > Security< / a >
< / li >
< li class = "toctree-l1" >
< a class = "" href = "../how-it-works/" > How it works< / a >
< / li >
< li class = "toctree-l1 current" >
< a class = "current" href = "./" > Class Reference< / a >
< ul class = "subnav" >
< li class = "toctree-l2" > < a href = "#graphqlgraphql" > GraphQL\GraphQL< / a > < / li >
< li class = "toctree-l2" > < a href = "#graphqltypedefinitiontype" > GraphQL\Type\Definition\Type< / a > < / li >
< li class = "toctree-l2" > < a href = "#graphqltypedefinitionresolveinfo" > GraphQL\Type\Definition\ResolveInfo< / a > < / li >
2018-04-20 12:39:52 +03:00
< li class = "toctree-l2" > < a href = "#graphqllanguagedirectivelocation" > GraphQL\Language\DirectiveLocation< / a > < / li >
2017-08-20 19:28:59 +03:00
< li class = "toctree-l2" > < a href = "#graphqltypeschemaconfig" > GraphQL\Type\SchemaConfig< / a > < / li >
< li class = "toctree-l2" > < a href = "#graphqltypeschema" > GraphQL\Type\Schema< / a > < / li >
< li class = "toctree-l2" > < a href = "#graphqllanguageparser" > GraphQL\Language\Parser< / a > < / li >
< li class = "toctree-l2" > < a href = "#graphqllanguageprinter" > GraphQL\Language\Printer< / a > < / li >
< li class = "toctree-l2" > < a href = "#graphqllanguagevisitor" > GraphQL\Language\Visitor< / a > < / li >
< li class = "toctree-l2" > < a href = "#graphqllanguageastnodekind" > GraphQL\Language\AST\NodeKind< / a > < / li >
< li class = "toctree-l2" > < a href = "#graphqlexecutorexecutor" > GraphQL\Executor\Executor< / a > < / li >
< li class = "toctree-l2" > < a href = "#graphqlexecutorexecutionresult" > GraphQL\Executor\ExecutionResult< / a > < / li >
< li class = "toctree-l2" > < a href = "#graphqlexecutorpromisepromiseadapter" > GraphQL\Executor\Promise\PromiseAdapter< / a > < / li >
< li class = "toctree-l2" > < a href = "#graphqlvalidatordocumentvalidator" > GraphQL\Validator\DocumentValidator< / a > < / li >
< li class = "toctree-l2" > < a href = "#graphqlerrorerror" > GraphQL\Error\Error< / a > < / li >
< li class = "toctree-l2" > < a href = "#graphqlerrorwarning" > GraphQL\Error\Warning< / a > < / li >
< li class = "toctree-l2" > < a href = "#graphqlerrorclientaware" > GraphQL\Error\ClientAware< / a > < / li >
< li class = "toctree-l2" > < a href = "#graphqlerrordebug" > GraphQL\Error\Debug< / a > < / li >
< li class = "toctree-l2" > < a href = "#graphqlerrorformattederror" > GraphQL\Error\FormattedError< / a > < / li >
< li class = "toctree-l2" > < a href = "#graphqlserverstandardserver" > GraphQL\Server\StandardServer< / a > < / li >
< li class = "toctree-l2" > < a href = "#graphqlserverserverconfig" > GraphQL\Server\ServerConfig< / a > < / li >
< li class = "toctree-l2" > < a href = "#graphqlserverhelper" > GraphQL\Server\Helper< / a > < / li >
< li class = "toctree-l2" > < a href = "#graphqlserveroperationparams" > GraphQL\Server\OperationParams< / a > < / li >
< li class = "toctree-l2" > < a href = "#graphqlutilsbuildschema" > GraphQL\Utils\BuildSchema< / a > < / li >
< li class = "toctree-l2" > < a href = "#graphqlutilsast" > GraphQL\Utils\AST< / a > < / li >
< li class = "toctree-l2" > < a href = "#graphqlutilsschemaprinter" > GraphQL\Utils\SchemaPrinter< / a > < / li >
< / ul >
< / li >
< / ul >
< / div >
< / nav >
< section data-toggle = "wy-nav-shift" class = "wy-nav-content-wrap" >
< nav class = "wy-nav-top" role = "navigation" aria-label = "top navigation" >
< i data-toggle = "wy-nav-top" class = "fa fa-bars" > < / i >
< a href = ".." > graphql-php< / a >
< / nav >
< div class = "wy-nav-content" >
< div class = "rst-content" >
< div role = "navigation" aria-label = "breadcrumbs navigation" >
< ul class = "wy-breadcrumbs" >
< li > < a href = ".." > Docs< / a > » < / li >
< li > Class Reference< / li >
< li class = "wy-breadcrumbs-aside" >
< / li >
< / ul >
< hr / >
< / div >
< div role = "main" >
< div class = "section" >
< h1 id = "graphqlgraphql" > GraphQL\GraphQL< / h1 >
< p > This is the primary facade for fulfilling GraphQL operations.
See < a href = "../executing-queries/" > related documentation< / a > .< / p >
< p > < strong > Class Methods:< / strong > < / p >
< pre > < code class = "php" > /**
* Executes graphql query.
*
* More sophisticated GraphQL servers, such as those which persist queries,
* may wish to separate the validation and execution phases to a static time
* tooling step, and a server runtime step.
*
* Available options:
*
* schema:
* The GraphQL type system to use when validating and executing a query.
* source:
* A GraphQL language formatted string representing the requested operation.
* 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
* variableValues:
* A mapping of variable name to runtime value to use for all variables
* defined in the requestString.
* operationName:
* The name of the operation to use if requestString contains multiple
* possible operations. Can be omitted if requestString contains only
* one operation.
* fieldResolver:
* A resolver function to use when one is not provided by the schema.
* If not provided, the default field resolver is used (which looks for a
* value on the source value with the field's name).
* validationRules:
* A set of rules for query validation step. Default value is all available rules.
* Empty array would allow to skip query validation (may be convenient for persisted
* queries which are validated before persisting and assumed valid during execution)
*
* @param string|DocumentNode $source
2018-11-27 16:10:17 +03:00
* @param mixed $rootValue
* @param mixed $context
* @param mixed[]|null $variableValues
* @param ValidationRule[] $validationRules
2017-08-20 19:28:59 +03:00
*
2018-11-27 16:10:17 +03:00
* @api
2017-08-20 19:28:59 +03:00
*/
static function executeQuery(
GraphQL\Type\Schema $schema,
$source,
$rootValue = null,
$context = null,
$variableValues = null,
2018-11-27 16:10:17 +03:00
string $operationName = null,
2017-08-20 19:28:59 +03:00
callable $fieldResolver = null,
array $validationRules = null
)
< / code > < / pre >
< pre > < code class = "php" > /**
* Same as executeQuery(), but requires PromiseAdapter and always returns a Promise.
* Useful for Async PHP platforms.
*
2018-11-27 16:10:17 +03:00
* @param string|DocumentNode $source
* @param mixed $rootValue
* @param mixed $context
* @param mixed[]|null $variableValues
* @param ValidationRule[]|null $validationRules
2017-08-20 19:28:59 +03:00
*
2018-11-27 16:10:17 +03:00
* @api
2017-08-20 19:28:59 +03:00
*/
static function promiseToExecute(
GraphQL\Executor\Promise\PromiseAdapter $promiseAdapter,
GraphQL\Type\Schema $schema,
$source,
$rootValue = null,
$context = null,
$variableValues = null,
2018-11-27 16:10:17 +03:00
string $operationName = null,
2017-08-20 19:28:59 +03:00
callable $fieldResolver = null,
array $validationRules = null
)
< / code > < / pre >
< pre > < code class = "php" > /**
* Returns directives defined in GraphQL spec
*
* @return Directive[]
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
static function getStandardDirectives()
< / code > < / pre >
< pre > < code class = "php" > /**
* Returns types defined in GraphQL spec
*
* @return Type[]
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
static function getStandardTypes()
< / code > < / pre >
2018-11-27 16:10:17 +03:00
< pre > < code class = "php" > /**
* 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)
< / code > < / pre >
2017-08-20 19:28:59 +03:00
< pre > < code class = "php" > /**
* Returns standard validation rules implementing GraphQL spec
*
2018-11-27 16:10:17 +03:00
* @return ValidationRule[]
*
2017-08-20 19:28:59 +03:00
* @api
*/
static function getStandardValidationRules()
< / code > < / pre >
2018-11-27 16:10:17 +03:00
< pre > < code class = "php" > /**
* Set default resolver implementation
*
* @api
*/
static function setDefaultFieldResolver(callable $fn)
< / code > < / pre >
2017-08-20 19:28:59 +03:00
< h1 id = "graphqltypedefinitiontype" > GraphQL\Type\Definition\Type< / h1 >
< p > Registry of standard GraphQL types
and a base class for all other types.< / p >
< p > < strong > Class Methods:< / strong > < / p >
< pre > < code class = "php" > /**
* @return IDType
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
static function id()
< / code > < / pre >
< pre > < code class = "php" > /**
* @return StringType
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
static function string()
< / code > < / pre >
< pre > < code class = "php" > /**
* @return BooleanType
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
static function boolean()
< / code > < / pre >
< pre > < code class = "php" > /**
* @return IntType
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
static function int()
< / code > < / pre >
< pre > < code class = "php" > /**
* @return FloatType
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
static function float()
< / code > < / pre >
< pre > < code class = "php" > /**
2018-04-20 12:39:52 +03:00
* @param Type|ObjectType|InterfaceType|UnionType|ScalarType|InputObjectType|EnumType|ListOfType|NonNull $wrappedType
2018-11-27 16:10:17 +03:00
*
2017-08-20 19:28:59 +03:00
* @return ListOfType
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
static function listOf($wrappedType)
< / code > < / pre >
< pre > < code class = "php" > /**
2019-05-29 14:08:49 +03:00
* @param ObjectType|InterfaceType|UnionType|ScalarType|InputObjectType|EnumType|ListOfType $wrappedType
2018-11-27 16:10:17 +03:00
*
2017-08-20 19:28:59 +03:00
* @return NonNull
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
static function nonNull($wrappedType)
< / code > < / pre >
< pre > < code class = "php" > /**
* @param Type $type
2018-11-27 16:10:17 +03:00
*
2017-08-20 19:28:59 +03:00
* @return bool
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
static function isInputType($type)
< / code > < / pre >
< pre > < code class = "php" > /**
2018-11-27 16:10:17 +03:00
* @param Type $type
*
* @return ObjectType|InterfaceType|UnionType|ScalarType|InputObjectType|EnumType
*
2017-08-20 19:28:59 +03:00
* @api
2018-11-27 16:10:17 +03:00
*/
static function getNamedType($type)
< / code > < / pre >
< pre > < code class = "php" > /**
2017-08-20 19:28:59 +03:00
* @param Type $type
2018-11-27 16:10:17 +03:00
*
2017-08-20 19:28:59 +03:00
* @return bool
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
static function isOutputType($type)
< / code > < / pre >
< pre > < code class = "php" > /**
2018-11-27 16:10:17 +03:00
* @param Type $type
*
2017-08-20 19:28:59 +03:00
* @return bool
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
static function isLeafType($type)
< / code > < / pre >
< pre > < code class = "php" > /**
* @param Type $type
2018-11-27 16:10:17 +03:00
*
2017-08-20 19:28:59 +03:00
* @return bool
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
static function isCompositeType($type)
< / code > < / pre >
< pre > < code class = "php" > /**
* @param Type $type
2018-11-27 16:10:17 +03:00
*
2017-08-20 19:28:59 +03:00
* @return bool
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
static function isAbstractType($type)
< / code > < / pre >
2018-04-20 12:39:52 +03:00
< pre > < code class = "php" > /**
* @param Type $type
2018-11-27 16:10:17 +03:00
*
2018-04-20 12:39:52 +03:00
* @return bool
2018-11-27 16:10:17 +03:00
*
* @api
2018-04-20 12:39:52 +03:00
*/
static function isType($type)
< / code > < / pre >
2017-08-20 19:28:59 +03:00
< pre > < code class = "php" > /**
* @param Type $type
2018-11-27 16:10:17 +03:00
*
2019-05-29 14:08:49 +03:00
* @return ObjectType|InterfaceType|UnionType|ScalarType|InputObjectType|EnumType|ListOfType
2018-11-27 16:10:17 +03:00
*
2017-08-20 19:28:59 +03:00
* @api
*/
2018-11-27 16:10:17 +03:00
static function getNullableType($type)
2017-08-20 19:28:59 +03:00
< / code > < / pre >
< h1 id = "graphqltypedefinitionresolveinfo" > GraphQL\Type\Definition\ResolveInfo< / h1 >
< p > Structure containing information useful for field resolution process.
Passed as 3rd argument to every field resolver. See < a href = "../data-fetching/" > docs on field resolving (data fetching)< / a > .< / p >
< p > < strong > Class Props:< / strong > < / p >
< pre > < code class = "php" > /**
* The name of the field being resolved
*
* @api
2019-05-29 14:08:49 +03:00
* @var string|null
2017-08-20 19:28:59 +03:00
*/
public $fieldName;
/**
* AST of all nodes referencing this field in the query.
*
* @api
2019-05-29 14:08:49 +03:00
* @var FieldNode[]|null
2017-08-20 19:28:59 +03:00
*/
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
*
* @api
2019-05-29 14:08:49 +03:00
* @var ObjectType|null
2017-08-20 19:28:59 +03:00
*/
public $parentType;
/**
* Path to this field from the very root value
*
* @api
2019-05-29 14:08:49 +03:00
* @var string[]
2017-08-20 19:28:59 +03:00
*/
public $path;
/**
* Instance of a schema used for execution
*
* @api
2018-11-27 16:10:17 +03:00
* @var Schema|null
2017-08-20 19:28:59 +03:00
*/
public $schema;
/**
* AST of all fragments defined in query
*
* @api
2019-05-29 14:08:49 +03:00
* @var FragmentDefinitionNode[]|null
2017-08-20 19:28:59 +03:00
*/
public $fragments;
/**
* Root value passed to query execution
*
* @api
2018-11-27 16:10:17 +03:00
* @var mixed|null
2017-08-20 19:28:59 +03:00
*/
public $rootValue;
/**
* AST of operation definition node (query, mutation)
*
* @api
2018-11-27 16:10:17 +03:00
* @var OperationDefinitionNode|null
2017-08-20 19:28:59 +03:00
*/
public $operation;
/**
* Array of variables passed to query execution
*
* @api
2019-05-29 14:08:49 +03:00
* @var mixed[]|null
2017-08-20 19:28:59 +03:00
*/
public $variableValues;
< / code > < / pre >
< p > < strong > Class Methods:< / strong > < / p >
< pre > < code class = "php" > /**
* Helper method that returns names of all fields selected in query for
* $this-> fieldName up to $depth levels
*
* Example:
* query MyQuery{
* {
* root {
* id,
* nested {
* nested1
* nested2 {
* nested3
* }
* }
* }
* }
*
* Given this ResolveInfo instance is a part of " root" field resolution, and $depth === 1,
* method will return:
* [
* 'id' => true,
* 'nested' => [
* nested1 => true,
* nested2 => true
* ]
* ]
*
* 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.
*
* @param int $depth How many levels to include in output
2018-11-27 16:10:17 +03:00
*
* @return bool[]
*
* @api
2017-08-20 19:28:59 +03:00
*/
function getFieldSelection($depth = 0)
< / code > < / pre >
2018-04-20 12:39:52 +03:00
< h1 id = "graphqllanguagedirectivelocation" > GraphQL\Language\DirectiveLocation< / h1 >
2017-08-20 19:28:59 +03:00
< p > List of available directive locations< / p >
< p > < strong > Class Constants:< / strong > < / p >
2018-04-20 12:39:52 +03:00
< pre > < code class = "php" > const QUERY = " QUERY" ;
2017-08-20 19:28:59 +03:00
const MUTATION = " MUTATION" ;
2018-04-20 12:39:52 +03:00
const SUBSCRIPTION = " SUBSCRIPTION" ;
const FIELD = " FIELD" ;
2017-08-20 19:28:59 +03:00
const FRAGMENT_DEFINITION = " FRAGMENT_DEFINITION" ;
2018-04-20 12:39:52 +03:00
const FRAGMENT_SPREAD = " FRAGMENT_SPREAD" ;
2017-08-20 19:28:59 +03:00
const INLINE_FRAGMENT = " INLINE_FRAGMENT" ;
2018-04-20 12:39:52 +03:00
const SCHEMA = " SCHEMA" ;
2017-08-20 19:28:59 +03:00
const SCALAR = " SCALAR" ;
2018-04-20 12:39:52 +03:00
const OBJECT = " OBJECT" ;
2017-08-20 19:28:59 +03:00
const FIELD_DEFINITION = " FIELD_DEFINITION" ;
const ARGUMENT_DEFINITION = " ARGUMENT_DEFINITION" ;
2018-04-20 12:39:52 +03:00
const IFACE = " INTERFACE" ;
const UNION = " UNION" ;
2017-08-20 19:28:59 +03:00
const ENUM = " ENUM" ;
const ENUM_VALUE = " ENUM_VALUE" ;
2018-04-20 12:39:52 +03:00
const INPUT_OBJECT = " INPUT_OBJECT" ;
2017-08-20 19:28:59 +03:00
const INPUT_FIELD_DEFINITION = " INPUT_FIELD_DEFINITION" ;
< / code > < / pre >
< h1 id = "graphqltypeschemaconfig" > GraphQL\Type\SchemaConfig< / h1 >
< p > Schema configuration class.
Could be passed directly to schema constructor. List of options accepted by < strong > create< / strong > method is
< a href = "../type-system/schema/#configuration-options" > described in docs< / a > .< / p >
< p > Usage example:< / p >
< pre > < code > $config = SchemaConfig::create()
-> setQuery($myQueryType)
-> setTypeLoader($myTypeLoader);
$schema = new Schema($config);
< / code > < / pre >
< p > < strong > Class Methods:< / strong > < / p >
< pre > < code class = "php" > /**
* Converts an array of options to instance of SchemaConfig
* (or just returns empty config when array is not passed).
*
2018-11-27 16:10:17 +03:00
* @param mixed[] $options
*
2017-08-20 19:28:59 +03:00
* @return SchemaConfig
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
static function create(array $options = [])
< / code > < / pre >
< pre > < code class = "php" > /**
2018-11-27 16:10:17 +03:00
* @return ObjectType
*
2017-08-20 19:28:59 +03:00
* @api
*/
2018-11-27 16:10:17 +03:00
function getQuery()
2017-08-20 19:28:59 +03:00
< / code > < / pre >
< pre > < code class = "php" > /**
2018-11-27 16:10:17 +03:00
* @param ObjectType $query
*
2017-08-20 19:28:59 +03:00
* @return SchemaConfig
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
2018-11-27 16:10:17 +03:00
function setQuery($query)
2017-08-20 19:28:59 +03:00
< / code > < / pre >
< pre > < code class = "php" > /**
2018-11-27 16:10:17 +03:00
* @return ObjectType
*
2017-08-20 19:28:59 +03:00
* @api
*/
2018-11-27 16:10:17 +03:00
function getMutation()
2017-08-20 19:28:59 +03:00
< / code > < / pre >
< pre > < code class = "php" > /**
2018-11-27 16:10:17 +03:00
* @param ObjectType $mutation
*
2017-08-20 19:28:59 +03:00
* @return SchemaConfig
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
2018-11-27 16:10:17 +03:00
function setMutation($mutation)
2017-08-20 19:28:59 +03:00
< / code > < / pre >
< pre > < code class = "php" > /**
2018-11-27 16:10:17 +03:00
* @return ObjectType
*
2017-08-20 19:28:59 +03:00
* @api
*/
2018-11-27 16:10:17 +03:00
function getSubscription()
2017-08-20 19:28:59 +03:00
< / code > < / pre >
< pre > < code class = "php" > /**
2018-11-27 16:10:17 +03:00
* @param ObjectType $subscription
*
2017-08-20 19:28:59 +03:00
* @return SchemaConfig
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
2018-11-27 16:10:17 +03:00
function setSubscription($subscription)
2017-08-20 19:28:59 +03:00
< / code > < / pre >
< pre > < code class = "php" > /**
2018-11-27 16:10:17 +03:00
* @return Type[]
*
2017-08-20 19:28:59 +03:00
* @api
*/
2018-11-27 16:10:17 +03:00
function getTypes()
2017-08-20 19:28:59 +03:00
< / code > < / pre >
< pre > < code class = "php" > /**
2018-11-27 16:10:17 +03:00
* @param Type[]|callable $types
*
* @return SchemaConfig
*
2017-08-20 19:28:59 +03:00
* @api
*/
2018-11-27 16:10:17 +03:00
function setTypes($types)
2017-08-20 19:28:59 +03:00
< / code > < / pre >
< pre > < code class = "php" > /**
2018-11-27 16:10:17 +03:00
* @return Directive[]
*
2017-08-20 19:28:59 +03:00
* @api
*/
2018-11-27 16:10:17 +03:00
function getDirectives()
2017-08-20 19:28:59 +03:00
< / code > < / pre >
< pre > < code class = "php" > /**
2018-11-27 16:10:17 +03:00
* @param Directive[] $directives
*
* @return SchemaConfig
*
2017-08-20 19:28:59 +03:00
* @api
*/
2018-11-27 16:10:17 +03:00
function setDirectives(array $directives)
2017-08-20 19:28:59 +03:00
< / code > < / pre >
< pre > < code class = "php" > /**
2018-11-27 16:10:17 +03:00
* @return callable
*
2017-08-20 19:28:59 +03:00
* @api
*/
2018-11-27 16:10:17 +03:00
function getTypeLoader()
2017-08-20 19:28:59 +03:00
< / code > < / pre >
< pre > < code class = "php" > /**
2018-11-27 16:10:17 +03:00
* @return SchemaConfig
*
2017-08-20 19:28:59 +03:00
* @api
*/
2018-11-27 16:10:17 +03:00
function setTypeLoader(callable $typeLoader)
2017-08-20 19:28:59 +03:00
< / code > < / pre >
< h1 id = "graphqltypeschema" > GraphQL\Type\Schema< / h1 >
< p > Schema Definition (see < a href = "../type-system/schema/" > related docs< / a > )< / p >
< p > A Schema is created by supplying the root types of each type of operation:
query, mutation (optional) and subscription (optional). A schema definition is
then supplied to the validator and executor. Usage Example:< / p >
< pre > < code > $schema = new GraphQL\Type\Schema([
'query' => $MyAppQueryRootType,
'mutation' => $MyAppMutationRootType,
]);
< / code > < / pre >
< p > Or using Schema Config instance:< / p >
< pre > < code > $config = GraphQL\Type\SchemaConfig::create()
-> setQuery($MyAppQueryRootType)
-> setMutation($MyAppMutationRootType);
$schema = new GraphQL\Type\Schema($config);
< / code > < / pre >
< p > < strong > Class Methods:< / strong > < / p >
< pre > < code class = "php" > /**
2018-11-27 16:10:17 +03:00
* @param mixed[]|SchemaConfig $config
2017-08-20 19:28:59 +03:00
*
* @api
*/
function __construct($config)
< / code > < / pre >
< pre > < code class = "php" > /**
2018-11-27 16:10:17 +03:00
* 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.
*
* @return Type[]
*
* @api
*/
function getTypeMap()
< / code > < / pre >
< pre > < code class = "php" > /**
* Returns a list of directives supported by this schema
*
* @return Directive[]
2017-08-20 19:28:59 +03:00
*
* @api
2018-11-27 16:10:17 +03:00
*/
function getDirectives()
< / code > < / pre >
< pre > < code class = "php" > /**
* Returns schema query type
*
2017-08-20 19:28:59 +03:00
* @return ObjectType
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
function getQueryType()
< / code > < / pre >
< pre > < code class = "php" > /**
* Returns schema mutation type
*
* @return ObjectType|null
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
function getMutationType()
< / code > < / pre >
< pre > < code class = "php" > /**
* Returns schema subscription
*
* @return ObjectType|null
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
function getSubscriptionType()
< / code > < / pre >
< pre > < code class = "php" > /**
* @return SchemaConfig
*
* @api
*/
2018-11-27 16:10:17 +03:00
function getConfig()
2017-08-20 19:28:59 +03:00
< / code > < / pre >
< pre > < code class = "php" > /**
* Returns type by it's name
*
* @param string $name
2018-11-27 16:10:17 +03:00
*
* @return Type|null
*
* @api
2017-08-20 19:28:59 +03:00
*/
function getType($name)
< / code > < / pre >
< pre > < code class = "php" > /**
* Returns all possible concrete types for given abstract type
* (implementations for interfaces and members of union type for unions)
*
* This operation requires full schema scan. Do not use in production environment.
*
* @return ObjectType[]
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
function getPossibleTypes(GraphQL\Type\Definition\AbstractType $abstractType)
< / code > < / pre >
< pre > < code class = "php" > /**
* Returns true if object type is concrete type of given abstract type
* (implementation for interfaces and members of union type for unions)
*
* @return bool
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
function isPossibleType(
GraphQL\Type\Definition\AbstractType $abstractType,
GraphQL\Type\Definition\ObjectType $possibleType
)
< / code > < / pre >
< pre > < code class = "php" > /**
* Returns instance of directive by name
*
2018-11-27 16:10:17 +03:00
* @param string $name
*
2017-08-20 19:28:59 +03:00
* @return Directive
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
function getDirective($name)
< / code > < / pre >
2018-04-20 12:39:52 +03:00
< pre > < code class = "php" > /**
* Validates schema.
*
* This operation requires full schema scan. Do not use in production environment.
*
2018-11-27 16:10:17 +03:00
* @throws InvariantViolation
*
2018-04-20 12:39:52 +03:00
* @api
*/
2018-11-27 16:10:17 +03:00
function assertValid()
2018-04-20 12:39:52 +03:00
< / code > < / pre >
2017-08-20 19:28:59 +03:00
< pre > < code class = "php" > /**
* Validates schema.
*
* This operation requires full schema scan. Do not use in production environment.
*
2018-11-27 16:10:17 +03:00
* @return InvariantViolation[]|Error[]
*
2017-08-20 19:28:59 +03:00
* @api
*/
2018-11-27 16:10:17 +03:00
function validate()
2017-08-20 19:28:59 +03:00
< / code > < / pre >
< h1 id = "graphqllanguageparser" > GraphQL\Language\Parser< / h1 >
< p > Parses string containing GraphQL query or < a href = "../type-system/type-language/" > type definition< / a > to Abstract Syntax Tree.< / p >
< p > < strong > Class Methods:< / strong > < / p >
< pre > < code class = "php" > /**
* Given a GraphQL source, parses it into a `GraphQL\Language\AST\DocumentNode`.
* Throws `GraphQL\Error\SyntaxError` if a syntax error is encountered.
*
* Available options:
*
* noLocation: boolean,
2018-11-27 16:10:17 +03:00
* (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.
2017-08-20 19:28:59 +03:00
*
2018-04-20 12:39:52 +03:00
* experimentalFragmentVariables: boolean,
2018-11-27 16:10:17 +03:00
* (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.
2018-04-20 12:39:52 +03:00
*
2018-11-27 16:10:17 +03:00
* The syntax is identical to normal, query-defined variables. For example:
2018-04-20 12:39:52 +03:00
*
2018-11-27 16:10:17 +03:00
* fragment A($var: Boolean = false) on T {
* ...
* }
2018-04-20 12:39:52 +03:00
*
2018-11-27 16:10:17 +03:00
* Note: this feature is experimental and may change or be removed in the
* future.)
2018-04-20 12:39:52 +03:00
*
2017-08-20 19:28:59 +03:00
* @param Source|string $source
2018-11-27 16:10:17 +03:00
* @param bool[] $options
*
2017-08-20 19:28:59 +03:00
* @return DocumentNode
2018-11-27 16:10:17 +03:00
*
2018-04-20 12:39:52 +03:00
* @throws SyntaxError
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
static function parse($source, array $options = [])
< / code > < / pre >
< pre > < code class = "php" > /**
* Given a string containing a GraphQL value (ex. `[42]`), parse the AST for
* that value.
* Throws `GraphQL\Error\SyntaxError` if a syntax error is encountered.
*
* This is useful within tools that operate upon GraphQL Values directly and
* in isolation of complete GraphQL documents.
*
* Consider providing the results to the utility function: `GraphQL\Utils\AST::valueFromAST()`.
*
* @param Source|string $source
2018-11-27 16:10:17 +03:00
* @param bool[] $options
*
2017-08-20 19:28:59 +03:00
* @return BooleanValueNode|EnumValueNode|FloatValueNode|IntValueNode|ListValueNode|ObjectValueNode|StringValueNode|VariableNode
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
static function parseValue($source, array $options = [])
< / code > < / pre >
< pre > < code class = "php" > /**
* Given a string containing a GraphQL Type (ex. `[Int!]`), parse the AST for
* that type.
* Throws `GraphQL\Error\SyntaxError` if a syntax error is encountered.
*
* This is useful within tools that operate upon GraphQL Types directly and
* in isolation of complete GraphQL documents.
*
* Consider providing the results to the utility function: `GraphQL\Utils\AST::typeFromAST()`.
*
* @param Source|string $source
2018-11-27 16:10:17 +03:00
* @param bool[] $options
*
2017-08-20 19:28:59 +03:00
* @return ListTypeNode|NameNode|NonNullTypeNode
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
static function parseType($source, array $options = [])
< / code > < / pre >
< h1 id = "graphqllanguageprinter" > GraphQL\Language\Printer< / h1 >
< p > Prints AST to string. Capable of printing GraphQL queries and Type definition language.
Useful for pretty-printing queries or printing back AST for logging, documentation, etc.< / p >
< p > Usage example:< / p >
< pre > < code class = "php" > $query = 'query myQuery {someField}';
$ast = GraphQL\Language\Parser::parse($query);
$printed = GraphQL\Language\Printer::doPrint($ast);
< / code > < / pre >
< p > < strong > Class Methods:< / strong > < / p >
< pre > < code class = "php" > /**
* Prints AST to string. Capable of printing GraphQL queries and Type definition language.
*
* @param Node $ast
2018-11-27 16:10:17 +03:00
*
2017-08-20 19:28:59 +03:00
* @return string
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
static function doPrint($ast)
< / code > < / pre >
< h1 id = "graphqllanguagevisitor" > GraphQL\Language\Visitor< / h1 >
< p > Utility for efficient AST traversal and modification.< / p >
< p > < code > visit()< / code > will walk through an AST using a depth first traversal, calling
the visitor's enter function at each node in the traversal, and calling the
leave function after visiting that node and all of it's child nodes.< / p >
< p > By returning different values from the enter and leave functions, the
behavior of the visitor can be altered, including skipping over a sub-tree of
the AST (by returning false), editing the AST by returning a value or null
to remove the value, or to stop the whole traversal by returning BREAK.< / p >
< p > When using < code > visit()< / code > to edit an AST, the original AST will not be modified, and
a new version of the AST with the changes applied will be returned from the
visit function.< / p >
< pre > < code > $editedAST = Visitor::visit($ast, [
'enter' => function ($node, $key, $parent, $path, $ancestors) {
// return
// null: no action
// Visitor::skipNode(): skip visiting this node
// Visitor::stop(): stop visiting altogether
// Visitor::removeNode(): delete this node
// any value: replace this node with the returned value
},
'leave' => function ($node, $key, $parent, $path, $ancestors) {
// return
// null: no action
// Visitor::stop(): stop visiting altogether
// Visitor::removeNode(): delete this node
// any value: replace this node with the returned value
}
]);
< / code > < / pre >
< p > Alternatively to providing enter() and leave() functions, a visitor can
instead provide functions named the same as the < a href = "./#graphqllanguageastnodekind" > kinds of AST nodes< / a > ,
or enter/leave visitors at a named key, leading to four permutations of
visitor API:< / p >
< p > 1) Named visitors triggered when entering a node a specific kind.< / p >
< pre > < code > Visitor::visit($ast, [
'Kind' => function ($node) {
// enter the "Kind" node
}
]);
< / code > < / pre >
< p > 2) Named visitors that trigger upon entering and leaving a node of
a specific kind.< / p >
< pre > < code > Visitor::visit($ast, [
'Kind' => [
'enter' => function ($node) {
// enter the "Kind" node
}
'leave' => function ($node) {
// leave the "Kind" node
}
]
]);
< / code > < / pre >
< p > 3) Generic visitors that trigger upon entering and leaving any node.< / p >
< pre > < code > Visitor::visit($ast, [
'enter' => function ($node) {
// enter any node
},
'leave' => function ($node) {
// leave any node
}
]);
< / code > < / pre >
< p > 4) Parallel visitors for entering and leaving nodes of a specific kind.< / p >
< pre > < code > Visitor::visit($ast, [
'enter' => [
'Kind' => function($node) {
// enter the "Kind" node
}
},
'leave' => [
'Kind' => function ($node) {
// leave the "Kind" node
}
]
]);
< / code > < / pre >
< p > < strong > Class Methods:< / strong > < / p >
< pre > < code class = "php" > /**
* Visit the AST (see class description for details)
*
2018-11-27 16:10:17 +03:00
* @param Node|ArrayObject|stdClass $root
* @param callable[] $visitor
* @param mixed[]|null $keyMap
*
2017-08-20 19:28:59 +03:00
* @return Node|mixed
2018-11-27 16:10:17 +03:00
*
* @throws Exception
*
* @api
2017-08-20 19:28:59 +03:00
*/
static function visit($root, $visitor, $keyMap = null)
< / code > < / pre >
< pre > < code class = "php" > /**
* Returns marker for visitor break
*
* @return VisitorOperation
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
static function stop()
< / code > < / pre >
< pre > < code class = "php" > /**
* Returns marker for skipping current node
*
* @return VisitorOperation
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
static function skipNode()
< / code > < / pre >
< pre > < code class = "php" > /**
* Returns marker for removing a node
*
* @return VisitorOperation
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
static function removeNode()
< / code > < / pre >
< h1 id = "graphqllanguageastnodekind" > GraphQL\Language\AST\NodeKind< / h1 >
< p > < strong > Class Constants:< / strong > < / p >
< pre > < code class = "php" > const NAME = " Name" ;
const DOCUMENT = " Document" ;
const OPERATION_DEFINITION = " OperationDefinition" ;
const VARIABLE_DEFINITION = " VariableDefinition" ;
const VARIABLE = " Variable" ;
const SELECTION_SET = " SelectionSet" ;
const FIELD = " Field" ;
const ARGUMENT = " Argument" ;
const FRAGMENT_SPREAD = " FragmentSpread" ;
const INLINE_FRAGMENT = " InlineFragment" ;
const FRAGMENT_DEFINITION = " FragmentDefinition" ;
const INT = " IntValue" ;
const FLOAT = " FloatValue" ;
const STRING = " StringValue" ;
const BOOLEAN = " BooleanValue" ;
const ENUM = " EnumValue" ;
const NULL = " NullValue" ;
const LST = " ListValue" ;
const OBJECT = " ObjectValue" ;
const OBJECT_FIELD = " ObjectField" ;
const DIRECTIVE = " Directive" ;
const NAMED_TYPE = " NamedType" ;
const LIST_TYPE = " ListType" ;
const NON_NULL_TYPE = " NonNullType" ;
const SCHEMA_DEFINITION = " SchemaDefinition" ;
const OPERATION_TYPE_DEFINITION = " OperationTypeDefinition" ;
const SCALAR_TYPE_DEFINITION = " ScalarTypeDefinition" ;
const OBJECT_TYPE_DEFINITION = " ObjectTypeDefinition" ;
const FIELD_DEFINITION = " FieldDefinition" ;
const INPUT_VALUE_DEFINITION = " InputValueDefinition" ;
const INTERFACE_TYPE_DEFINITION = " InterfaceTypeDefinition" ;
const UNION_TYPE_DEFINITION = " UnionTypeDefinition" ;
const ENUM_TYPE_DEFINITION = " EnumTypeDefinition" ;
const ENUM_VALUE_DEFINITION = " EnumValueDefinition" ;
const INPUT_OBJECT_TYPE_DEFINITION = " InputObjectTypeDefinition" ;
2018-04-20 12:39:52 +03:00
const SCALAR_TYPE_EXTENSION = " ScalarTypeExtension" ;
const OBJECT_TYPE_EXTENSION = " ObjectTypeExtension" ;
const INTERFACE_TYPE_EXTENSION = " InterfaceTypeExtension" ;
const UNION_TYPE_EXTENSION = " UnionTypeExtension" ;
const ENUM_TYPE_EXTENSION = " EnumTypeExtension" ;
const INPUT_OBJECT_TYPE_EXTENSION = " InputObjectTypeExtension" ;
2017-08-20 19:28:59 +03:00
const DIRECTIVE_DEFINITION = " DirectiveDefinition" ;
2018-11-27 16:10:17 +03:00
const SCHEMA_EXTENSION = " SchemaExtension" ;
2017-08-20 19:28:59 +03:00
< / code > < / pre >
< h1 id = "graphqlexecutorexecutor" > GraphQL\Executor\Executor< / h1 >
< p > Implements the "Evaluating requests" section of the GraphQL specification.< / p >
< p > < strong > Class Methods:< / strong > < / p >
< pre > < code class = "php" > /**
* Executes DocumentNode against given $schema.
*
* Always returns ExecutionResult and never throws. All errors which occur during operation
* execution are collected in `$result-> errors`.
*
2018-11-27 16:10:17 +03:00
* @param mixed|null $rootValue
2019-05-29 14:08:49 +03:00
* @param mixed[]|null $contextValue
2018-11-27 16:10:17 +03:00
* @param mixed[]|ArrayAccess|null $variableValues
* @param string|null $operationName
2017-08-20 19:28:59 +03:00
*
* @return ExecutionResult|Promise
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
static function execute(
GraphQL\Type\Schema $schema,
2018-11-27 16:10:17 +03:00
GraphQL\Language\AST\DocumentNode $documentNode,
2017-08-20 19:28:59 +03:00
$rootValue = null,
$contextValue = null,
$variableValues = null,
$operationName = null,
callable $fieldResolver = null
)
< / code > < / pre >
< pre > < code class = "php" > /**
* Same as execute(), but requires promise adapter and returns a promise which is always
* fulfilled with an instance of ExecutionResult and never rejected.
*
* Useful for async PHP platforms.
*
2019-05-29 14:08:49 +03:00
* @param mixed[]|null $rootValue
* @param mixed[]|null $contextValue
2018-11-27 16:10:17 +03:00
* @param mixed[]|null $variableValues
* @param string|null $operationName
*
2017-08-20 19:28:59 +03:00
* @return Promise
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
static function promiseToExecute(
GraphQL\Executor\Promise\PromiseAdapter $promiseAdapter,
GraphQL\Type\Schema $schema,
2018-11-27 16:10:17 +03:00
GraphQL\Language\AST\DocumentNode $documentNode,
2017-08-20 19:28:59 +03:00
$rootValue = null,
$contextValue = null,
$variableValues = null,
$operationName = null,
callable $fieldResolver = null
)
< / code > < / pre >
< h1 id = "graphqlexecutorexecutionresult" > GraphQL\Executor\ExecutionResult< / h1 >
< p > Returned after < a href = "../executing-queries/" > query execution< / a > .
Represents both - result of successful execution and of a failed one
(with errors collected in < code > errors< / code > prop)< / p >
< p > Could be converted to < a href = "https://facebook.github.io/graphql/#sec-Response-Format" > spec-compliant< / a >
serializable array using < code > toArray()< / code > < / p >
< p > < strong > Class Props:< / strong > < / p >
< pre > < code class = "php" > /**
* Data collected from resolvers during query execution
*
* @api
2018-11-27 16:10:17 +03:00
* @var mixed[]
2017-08-20 19:28:59 +03:00
*/
public $data;
/**
* Errors registered during query execution.
*
* If an error was caused by exception thrown in resolver, $error-> getPrevious() would
* contain original exception.
*
* @api
2018-11-27 16:10:17 +03:00
* @var Error[]
2017-08-20 19:28:59 +03:00
*/
public $errors;
/**
* User-defined serializable array of extensions included in serialized result.
* Conforms to
*
* @api
2018-11-27 16:10:17 +03:00
* @var mixed[]
2017-08-20 19:28:59 +03:00
*/
public $extensions;
< / code > < / pre >
< p > < strong > Class Methods:< / strong > < / p >
< pre > < code class = "php" > /**
* Define custom error formatting (must conform to http://facebook.github.io/graphql/#sec-Errors)
*
* Expected signature is: function (GraphQL\Error\Error $error): array
*
* Default formatter is " GraphQL\Error\FormattedError::createFromException"
*
* Expected returned value must be an array:
* array(
* 'message' => 'errorMessage',
* // ... other keys
* );
*
2018-11-27 16:10:17 +03:00
* @return self
*
2017-08-20 19:28:59 +03:00
* @api
*/
function setErrorFormatter(callable $errorFormatter)
< / code > < / pre >
< pre > < code class = "php" > /**
* Define custom logic for error handling (filtering, logging, etc).
*
* Expected handler signature is: function (array $errors, callable $formatter): array
*
* Default handler is:
* function (array $errors, callable $formatter) {
* return array_map($formatter, $errors);
* }
*
2018-11-27 16:10:17 +03:00
* @return self
*
2017-08-20 19:28:59 +03:00
* @api
*/
function setErrorsHandler(callable $handler)
< / code > < / pre >
< pre > < code class = "php" > /**
* Converts GraphQL query result to spec-compliant serializable array using provided
* errors handler and formatter.
*
* 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
2018-11-27 16:10:17 +03:00
*
* @return mixed[]
*
* @api
2017-08-20 19:28:59 +03:00
*/
function toArray($debug = false)
< / code > < / pre >
< h1 id = "graphqlexecutorpromisepromiseadapter" > GraphQL\Executor\Promise\PromiseAdapter< / h1 >
< p > Provides a means for integration of async PHP platforms (< a href = "../data-fetching/#async-php" > related docs< / a > )< / p >
< p > < strong > Interface Methods:< / strong > < / p >
< pre > < code class = "php" > /**
* Return true if the value is a promise or a deferred of the underlying platform
*
* @param mixed $value
2018-11-27 16:10:17 +03:00
*
2017-08-20 19:28:59 +03:00
* @return bool
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
function isThenable($value)
< / code > < / pre >
< pre > < code class = "php" > /**
* Converts thenable of the underlying platform into GraphQL\Executor\Promise\Promise instance
*
* @param object $thenable
2018-11-27 16:10:17 +03:00
*
2017-08-20 19:28:59 +03:00
* @return Promise
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
function convertThenable($thenable)
< / code > < / pre >
< pre > < code class = "php" > /**
* 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.
*
* @return Promise
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
function then(
GraphQL\Executor\Promise\Promise $promise,
callable $onFulfilled = null,
callable $onRejected = null
)
< / code > < / pre >
< pre > < code class = "php" > /**
* Creates a Promise
*
* Expected resolver signature:
* function(callable $resolve, callable $reject)
*
* @return Promise
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
function create(callable $resolver)
< / code > < / pre >
< pre > < code class = "php" > /**
* Creates a fulfilled Promise for a value if the value is not a promise.
*
* @param mixed $value
2018-11-27 16:10:17 +03:00
*
2017-08-20 19:28:59 +03:00
* @return Promise
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
function createFulfilled($value = null)
< / code > < / pre >
< pre > < code class = "php" > /**
* 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.
*
2018-11-27 16:10:17 +03:00
* @param Throwable $reason
*
2017-08-20 19:28:59 +03:00
* @return Promise
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
function createRejected($reason)
< / code > < / pre >
< pre > < code class = "php" > /**
* Given an array of promises (or values), returns a promise that is fulfilled when all the
* items in the array are fulfilled.
*
2018-11-27 16:10:17 +03:00
* @param Promise[]|mixed[] $promisesOrValues Promises or values.
*
2017-08-20 19:28:59 +03:00
* @return Promise
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
function all(array $promisesOrValues)
< / code > < / pre >
< h1 id = "graphqlvalidatordocumentvalidator" > GraphQL\Validator\DocumentValidator< / h1 >
< p > Implements the "Validation" section of the spec.< / p >
< p > Validation runs synchronously, returning an array of encountered errors, or
an empty array if no errors were encountered and the document is valid.< / p >
< p > 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.< / p >
2018-11-27 16:10:17 +03:00
< p > Each validation rule is an instance of GraphQL\Validator\Rules\ValidationRule
2017-08-20 19:28:59 +03:00
which returns a visitor (see the < a href = "./#graphqllanguagevisitor" > GraphQL\Language\Visitor API< / a > ).< / p >
< p > Visitor methods are expected to return an instance of < a href = "./#graphqlerrorerror" > GraphQL\Error\Error< / a > ,
or array of such instances when invalid.< / p >
< p > Optionally a custom TypeInfo instance may be provided. If not provided, one
will be created from the provided schema.< / p >
< p > < strong > Class Methods:< / strong > < / p >
< pre > < code class = "php" > /**
* Primary method for query validation. See class description for details.
*
2018-11-27 16:10:17 +03:00
* @param ValidationRule[]|null $rules
*
2017-08-20 19:28:59 +03:00
* @return Error[]
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
static function validate(
GraphQL\Type\Schema $schema,
GraphQL\Language\AST\DocumentNode $ast,
array $rules = null,
GraphQL\Utils\TypeInfo $typeInfo = null
)
< / code > < / pre >
< pre > < code class = "php" > /**
* Returns all global validation rules.
*
2018-11-27 16:10:17 +03:00
* @return ValidationRule[]
*
2017-08-20 19:28:59 +03:00
* @api
*/
static function allRules()
< / code > < / pre >
< pre > < code class = "php" > /**
* Returns global validation rule by name. Standard rules are named by class name, so
* example usage for such rules:
*
* $rule = DocumentValidator::getRule(GraphQL\Validator\Rules\QueryComplexity::class);
*
* @param string $name
2018-11-27 16:10:17 +03:00
*
* @return ValidationRule
*
* @api
2017-08-20 19:28:59 +03:00
*/
static function getRule($name)
< / code > < / pre >
< pre > < code class = "php" > /**
* Add rule to list of global validation rules
*
* @api
*/
2018-11-27 16:10:17 +03:00
static function addRule(GraphQL\Validator\Rules\ValidationRule $rule)
2017-08-20 19:28:59 +03:00
< / code > < / pre >
< h1 id = "graphqlerrorerror" > GraphQL\Error\Error< / h1 >
< p > Describes an Error found during the parse, validate, or
execute phases of performing a GraphQL operation. In addition to a message
and stack trace, it also includes information about the locations in a
GraphQL document and/or execution result that correspond to the Error.< / p >
< p > When the error was caused by an exception thrown in resolver, original exception
is available via < code > getPrevious()< / code > .< / p >
< p > Also read related docs on < a href = "../error-handling/" > error handling< / a > < / p >
< p > Class extends standard PHP < code > \Exception< / code > , so all standard methods of base < code > \Exception< / code > class
are available in addition to those listed below.< / p >
< p > < strong > Class Constants:< / strong > < / p >
< pre > < code class = "php" > const CATEGORY_GRAPHQL = " graphql" ;
const CATEGORY_INTERNAL = " internal" ;
< / code > < / pre >
< p > < strong > Class Methods:< / strong > < / p >
< pre > < code class = "php" > /**
* An array of locations within the source GraphQL document which correspond to this error.
*
* Each entry has information about `line` and `column` within source GraphQL document:
* $location-> line;
* $location-> column;
*
* Errors during validation often contain multiple locations, for example to
* point out to field mentioned in multiple fragments. Errors during execution include a
* single location, the field which produced the error.
*
* @return SourceLocation[]
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
function getLocations()
< / code > < / pre >
< pre > < code class = "php" > /**
* Returns an array describing the path from the root value to the field which produced this error.
* Only included for execution errors.
*
2018-11-27 16:10:17 +03:00
* @return mixed[]|null
*
2017-08-20 19:28:59 +03:00
* @api
*/
function getPath()
< / code > < / pre >
< h1 id = "graphqlerrorwarning" > GraphQL\Error\Warning< / h1 >
< p > Encapsulates warnings produced by the library.< / p >
< p > Warnings can be suppressed (individually or all) if required.
Also it is possible to override warning handler (which is < strong > trigger_error()< / strong > by default)< / p >
< p > < strong > Class Constants:< / strong > < / p >
2018-04-20 12:39:52 +03:00
< pre > < code class = "php" > const WARNING_ASSIGN = 2;
2017-08-20 19:28:59 +03:00
const WARNING_CONFIG = 4;
const WARNING_FULL_SCHEMA_SCAN = 8;
const WARNING_CONFIG_DEPRECATION = 16;
const WARNING_NOT_A_TYPE = 32;
const ALL = 63;
< / code > < / pre >
< p > < strong > Class Methods:< / strong > < / p >
< pre > < code class = "php" > /**
* Sets warning handler which can intercept all system warnings.
* When not set, trigger_error() is used to notify about warnings.
*
* @api
*/
static function setWarningHandler(callable $warningHandler = null)
< / code > < / pre >
< pre > < code class = "php" > /**
* Suppress warning by id (has no effect when custom warning handler is set)
*
* Usage example:
* Warning::suppress(Warning::WARNING_NOT_A_TYPE)
*
* When passing true - suppresses all warnings.
*
* @param bool|int $suppress
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
2018-04-20 12:39:52 +03:00
static function suppress($suppress = true)
2017-08-20 19:28:59 +03:00
< / code > < / pre >
< pre > < code class = "php" > /**
* Re-enable previously suppressed warning by id
*
* Usage example:
* Warning::suppress(Warning::WARNING_NOT_A_TYPE)
*
* When passing true - re-enables all warnings.
*
* @param bool|int $enable
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
2018-04-20 12:39:52 +03:00
static function enable($enable = true)
2017-08-20 19:28:59 +03:00
< / code > < / pre >
< h1 id = "graphqlerrorclientaware" > GraphQL\Error\ClientAware< / h1 >
< p > This interface is used for < a href = "../error-handling/" > default error formatting< / a > .< / p >
< p > Only errors implementing this interface (and returning true from < code > isClientSafe()< / code > )
will be formatted with original error message.< / p >
< p > All other errors will be formatted with generic "Internal server error".< / p >
< p > < strong > Interface Methods:< / strong > < / p >
< pre > < code class = "php" > /**
* Returns true when exception message is safe to be displayed to a client.
*
* @return bool
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
function isClientSafe()
< / code > < / pre >
< pre > < code class = "php" > /**
* Returns string describing a category of the error.
*
* Value " graphql" is reserved for errors produced by query parsing or validation, do not use it.
*
* @return string
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
function getCategory()
< / code > < / pre >
< h1 id = "graphqlerrordebug" > GraphQL\Error\Debug< / h1 >
< p > Collection of flags for < a href = "../error-handling/#debugging-tools" > error debugging< / a > .< / p >
< p > < strong > Class Constants:< / strong > < / p >
< pre > < code class = "php" > const INCLUDE_DEBUG_MESSAGE = 1;
const INCLUDE_TRACE = 2;
const RETHROW_INTERNAL_EXCEPTIONS = 4;
2018-11-27 16:10:17 +03:00
const RETHROW_UNSAFE_EXCEPTIONS = 8;
2017-08-20 19:28:59 +03:00
< / code > < / pre >
< h1 id = "graphqlerrorformattederror" > GraphQL\Error\FormattedError< / h1 >
< p > This class is used for < a href = "../error-handling/" > default error formatting< / a > .
It converts PHP exceptions to < a href = "https://facebook.github.io/graphql/#sec-Errors" > spec-compliant errors< / a >
and provides tools for error debugging.< / p >
< p > < strong > Class Methods:< / strong > < / p >
< pre > < code class = "php" > /**
* Set default error message for internal errors formatted using createFormattedError().
* This value can be overridden by passing 3rd argument to `createFormattedError()`.
*
* @param string $msg
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
static function setInternalErrorMessage($msg)
< / code > < / pre >
< pre > < code class = "php" > /**
* Standard GraphQL error formatter. Converts any exception to array
* conforming to GraphQL spec.
*
* 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.
*
2018-11-27 16:10:17 +03:00
* @param Throwable $e
* @param bool|int $debug
* @param string $internalErrorMessage
*
* @return mixed[]
*
* @throws Throwable
*
2017-08-20 19:28:59 +03:00
* @api
*/
static function createFromException($e, $debug = false, $internalErrorMessage = null)
< / code > < / pre >
< pre > < code class = "php" > /**
* Returns error trace as serializable array
*
2018-11-27 16:10:17 +03:00
* @param Throwable $error
*
* @return mixed[]
*
2017-08-20 19:28:59 +03:00
* @api
*/
static function toSafeTrace($error)
< / code > < / pre >
< h1 id = "graphqlserverstandardserver" > GraphQL\Server\StandardServer< / h1 >
< p > GraphQL server compatible with both: < a href = "https://github.com/graphql/express-graphql" > express-graphql< / a >
and < a href = "https://github.com/apollographql/graphql-server" > Apollo Server< / a > .
Usage Example:< / p >
< pre > < code > $server = new StandardServer([
'schema' => $mySchema
]);
$server-> handleRequest();
< / code > < / pre >
< p > Or using < a href = "./#graphqlserverserverconfig" > ServerConfig< / a > instance:< / p >
< pre > < code > $config = GraphQL\Server\ServerConfig::create()
-> setSchema($mySchema)
-> setContext($myContext);
$server = new GraphQL\Server\StandardServer($config);
$server-> handleRequest();
< / code > < / pre >
< p > See < a href = "../executing-queries/#using-server" > dedicated section in docs< / a > for details.< / p >
< p > < strong > Class Methods:< / strong > < / p >
< pre > < code class = "php" > /**
* Converts and exception to error and sends spec-compliant HTTP 500 error.
* Useful when an exception is thrown somewhere outside of server execution context
* (e.g. during schema instantiation).
*
2018-11-27 16:10:17 +03:00
* @param Throwable $error
* @param bool $debug
* @param bool $exitWhenDone
*
2017-08-20 19:28:59 +03:00
* @api
*/
static function send500Error($error, $debug = false, $exitWhenDone = false)
< / code > < / pre >
< pre > < code class = "php" > /**
* Creates new instance of a standard GraphQL HTTP server
*
2018-11-27 16:10:17 +03:00
* @param ServerConfig|mixed[] $config
*
2017-08-20 19:28:59 +03:00
* @api
*/
function __construct($config)
< / code > < / pre >
< pre > < code class = "php" > /**
* Parses HTTP request, executes and emits response (using standard PHP `header` function and `echo`)
*
* By default (when $parsedBody is not set) it uses PHP globals to parse a request.
* It is possible to implement request parsing elsewhere (e.g. using framework Request instance)
* and then pass it to the server.
*
* See `executeRequest()` if you prefer to emit response yourself
* (e.g. using Response object of some framework)
*
* @param OperationParams|OperationParams[] $parsedBody
2018-11-27 16:10:17 +03:00
* @param bool $exitWhenDone
*
* @api
2017-08-20 19:28:59 +03:00
*/
function handleRequest($parsedBody = null, $exitWhenDone = false)
< / code > < / pre >
< pre > < code class = "php" > /**
* Executes GraphQL operation and returns execution result
* (or promise when promise adapter is different from SyncPromiseAdapter).
*
* By default (when $parsedBody is not set) it uses PHP globals to parse a request.
* It is possible to implement request parsing elsewhere (e.g. using framework Request instance)
* and then pass it to the server.
*
* PSR-7 compatible method executePsrRequest() does exactly this.
*
* @param OperationParams|OperationParams[] $parsedBody
2018-11-27 16:10:17 +03:00
*
2017-08-20 19:28:59 +03:00
* @return ExecutionResult|ExecutionResult[]|Promise
2018-11-27 16:10:17 +03:00
*
2017-08-20 19:28:59 +03:00
* @throws InvariantViolation
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
function executeRequest($parsedBody = null)
< / code > < / pre >
< pre > < code class = "php" > /**
* Executes PSR-7 request and fulfills PSR-7 response.
*
* See `executePsrRequest()` if you prefer to create response yourself
* (e.g. using specific JsonResponse instance of some framework).
*
* @return ResponseInterface|Promise
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
function processPsrRequest(
Psr\Http\Message\ServerRequestInterface $request,
Psr\Http\Message\ResponseInterface $response,
Psr\Http\Message\StreamInterface $writableBodyStream
)
< / code > < / pre >
< pre > < code class = "php" > /**
* Executes GraphQL operation and returns execution result
* (or promise when promise adapter is different from SyncPromiseAdapter)
*
* @return ExecutionResult|ExecutionResult[]|Promise
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
function executePsrRequest(Psr\Http\Message\ServerRequestInterface $request)
< / code > < / pre >
< pre > < code class = "php" > /**
* 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)
*
* @return Helper
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
function getHelper()
< / code > < / pre >
< h1 id = "graphqlserverserverconfig" > GraphQL\Server\ServerConfig< / h1 >
< p > Server configuration class.
Could be passed directly to server constructor. List of options accepted by < strong > create< / strong > method is
< a href = "../executing-queries/#server-configuration-options" > described in docs< / a > .< / p >
< p > Usage example:< / p >
< pre > < code > $config = GraphQL\Server\ServerConfig::create()
-> setSchema($mySchema)
-> setContext($myContext);
$server = new GraphQL\Server\StandardServer($config);
< / code > < / pre >
< p > < strong > Class Methods:< / strong > < / p >
< pre > < code class = "php" > /**
* Converts an array of options to instance of ServerConfig
* (or just returns empty config when array is not passed).
*
2018-11-27 16:10:17 +03:00
* @param mixed[] $config
*
2017-08-20 19:28:59 +03:00
* @return ServerConfig
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
static function create(array $config = [])
< / code > < / pre >
< pre > < code class = "php" > /**
2018-11-27 16:10:17 +03:00
* @return self
*
2017-08-20 19:28:59 +03:00
* @api
*/
function setSchema(GraphQL\Type\Schema $schema)
< / code > < / pre >
< pre > < code class = "php" > /**
2018-11-27 16:10:17 +03:00
* @param mixed|callable $context
*
* @return self
*
2017-08-20 19:28:59 +03:00
* @api
*/
function setContext($context)
< / code > < / pre >
< pre > < code class = "php" > /**
2018-11-27 16:10:17 +03:00
* @param mixed|callable $rootValue
*
* @return self
*
2017-08-20 19:28:59 +03:00
* @api
*/
function setRootValue($rootValue)
< / code > < / pre >
< pre > < code class = "php" > /**
* Expects function(Throwable $e) : array
*
2018-11-27 16:10:17 +03:00
* @return self
*
2017-08-20 19:28:59 +03:00
* @api
*/
function setErrorFormatter(callable $errorFormatter)
< / code > < / pre >
< pre > < code class = "php" > /**
* Expects function(array $errors, callable $formatter) : array
*
2018-11-27 16:10:17 +03:00
* @return self
*
2017-08-20 19:28:59 +03:00
* @api
*/
function setErrorsHandler(callable $handler)
< / code > < / pre >
< pre > < code class = "php" > /**
* Set validation rules for this server.
*
2018-11-27 16:10:17 +03:00
* @param ValidationRule[]|callable $validationRules
*
* @return self
*
2017-08-20 19:28:59 +03:00
* @api
*/
function setValidationRules($validationRules)
< / code > < / pre >
< pre > < code class = "php" > /**
2018-11-27 16:10:17 +03:00
* @return self
*
2017-08-20 19:28:59 +03:00
* @api
*/
function setFieldResolver(callable $fieldResolver)
< / code > < / pre >
< pre > < code class = "php" > /**
* Expects function($queryId, OperationParams $params) : string|DocumentNode
*
* This function must return query string or valid DocumentNode.
*
2018-11-27 16:10:17 +03:00
* @return self
*
2017-08-20 19:28:59 +03:00
* @api
*/
function setPersistentQueryLoader(callable $persistentQueryLoader)
< / code > < / pre >
< pre > < code class = "php" > /**
* Set response debug flags. See GraphQL\Error\Debug class for a list of all available flags
*
* @param bool|int $set
2018-11-27 16:10:17 +03:00
*
* @return self
*
* @api
2017-08-20 19:28:59 +03:00
*/
2018-04-20 12:39:52 +03:00
function setDebug($set = true)
2017-08-20 19:28:59 +03:00
< / code > < / pre >
< pre > < code class = "php" > /**
* Allow batching queries (disabled by default)
*
* @param bool $enableBatching
2018-11-27 16:10:17 +03:00
*
* @return self
*
* @api
2017-08-20 19:28:59 +03:00
*/
function setQueryBatching($enableBatching)
< / code > < / pre >
< pre > < code class = "php" > /**
2018-11-27 16:10:17 +03:00
* @return self
*
2017-08-20 19:28:59 +03:00
* @api
*/
function setPromiseAdapter(GraphQL\Executor\Promise\PromiseAdapter $promiseAdapter)
< / code > < / pre >
< h1 id = "graphqlserverhelper" > GraphQL\Server\Helper< / h1 >
< p > Contains functionality that could be re-used by various server implementations< / p >
< p > < strong > Class Methods:< / strong > < / p >
< pre > < code class = "php" > /**
* Parses HTTP request using PHP globals and returns GraphQL OperationParams
* contained in this request. For batched requests it returns an array of OperationParams.
*
* This function does not check validity of these params
* (validation is performed separately in validateOperationParams() method).
*
* If $readRawBodyFn argument is not provided - will attempt to read raw request body
* from `php://input` stream.
*
* Internally it normalizes input to $method, $bodyParams and $queryParams and
* calls `parseRequestParams()` to produce actual return value.
*
* For PSR-7 request parsing use `parsePsrRequest()` instead.
*
* @return OperationParams|OperationParams[]
2018-11-27 16:10:17 +03:00
*
2017-08-20 19:28:59 +03:00
* @throws RequestError
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
function parseHttpRequest(callable $readRawBodyFn = null)
< / code > < / pre >
< pre > < code class = "php" > /**
* Parses normalized request params and returns instance of OperationParams
* or array of OperationParams in case of batch operation.
*
* Returned value is a suitable input for `executeOperation` or `executeBatch` (if array)
*
2018-11-27 16:10:17 +03:00
* @param string $method
* @param mixed[] $bodyParams
* @param mixed[] $queryParams
*
2017-08-20 19:28:59 +03:00
* @return OperationParams|OperationParams[]
2018-11-27 16:10:17 +03:00
*
2017-08-20 19:28:59 +03:00
* @throws RequestError
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
function parseRequestParams($method, array $bodyParams, array $queryParams)
< / code > < / pre >
< pre > < code class = "php" > /**
* 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[]
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
function validateOperationParams(GraphQL\Server\OperationParams $params)
< / code > < / pre >
< pre > < code class = "php" > /**
* Executes GraphQL operation with given server configuration and returns execution result
* (or promise when promise adapter is different from SyncPromiseAdapter)
*
* @return ExecutionResult|Promise
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
function executeOperation(GraphQL\Server\ServerConfig $config, GraphQL\Server\OperationParams $op)
< / code > < / pre >
< pre > < code class = "php" > /**
* Executes batched GraphQL operations with shared promise queue
* (thus, effectively batching deferreds|promises of all queries at once)
*
* @param OperationParams[] $operations
2018-11-27 16:10:17 +03:00
*
* @return ExecutionResult|ExecutionResult[]|Promise
*
* @api
2017-08-20 19:28:59 +03:00
*/
function executeBatch(GraphQL\Server\ServerConfig $config, array $operations)
< / code > < / pre >
< pre > < code class = "php" > /**
* Send response using standard PHP `header()` and `echo`.
*
* @param Promise|ExecutionResult|ExecutionResult[] $result
2018-11-27 16:10:17 +03:00
* @param bool $exitWhenDone
*
* @api
2017-08-20 19:28:59 +03:00
*/
function sendResponse($result, $exitWhenDone = false)
< / code > < / pre >
< pre > < code class = "php" > /**
* Converts PSR-7 request to OperationParams[]
*
2018-11-27 16:10:17 +03:00
* @return OperationParams[]|OperationParams
*
2017-08-20 19:28:59 +03:00
* @throws RequestError
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
function parsePsrRequest(Psr\Http\Message\ServerRequestInterface $request)
< / code > < / pre >
< pre > < code class = "php" > /**
* Converts query execution result to PSR-7 response
*
* @param Promise|ExecutionResult|ExecutionResult[] $result
2018-11-27 16:10:17 +03:00
*
2017-08-20 19:28:59 +03:00
* @return Promise|ResponseInterface
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
function toPsrResponse(
$result,
Psr\Http\Message\ResponseInterface $response,
Psr\Http\Message\StreamInterface $writableBodyStream
)
< / code > < / pre >
< h1 id = "graphqlserveroperationparams" > GraphQL\Server\OperationParams< / h1 >
< p > Structure representing parsed HTTP parameters for GraphQL operation< / p >
< p > < strong > Class Props:< / strong > < / p >
< pre > < code class = "php" > /**
* Id of the query (when using persistent queries).
*
* Valid aliases (case-insensitive):
* - id
* - queryId
* - documentId
*
* @api
* @var string
*/
public $queryId;
/**
* @api
* @var string
*/
public $query;
/**
* @api
* @var string
*/
public $operation;
/**
* @api
2018-11-27 16:10:17 +03:00
* @var mixed[]|null
2017-08-20 19:28:59 +03:00
*/
public $variables;
< / code > < / pre >
< p > < strong > Class Methods:< / strong > < / p >
< pre > < code class = "php" > /**
* Creates an instance from given array
*
2018-11-27 16:10:17 +03:00
* @param mixed[] $params
* @param bool $readonly
*
2017-08-20 19:28:59 +03:00
* @return OperationParams
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
static function create(array $params, $readonly = false)
< / code > < / pre >
< pre > < code class = "php" > /**
* @param string $key
2018-11-27 16:10:17 +03:00
*
2017-08-20 19:28:59 +03:00
* @return mixed
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
function getOriginalInput($key)
< / code > < / pre >
< pre > < code class = "php" > /**
* Indicates that operation is executed in read-only context
* (e.g. via HTTP GET request)
*
* @return bool
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
function isReadOnly()
< / code > < / pre >
< h1 id = "graphqlutilsbuildschema" > GraphQL\Utils\BuildSchema< / h1 >
< p > Build instance of < code > GraphQL\Type\Schema< / code > out of type language definition (string or parsed AST)
See < a href = "../type-system/type-language/" > section in docs< / a > for details.< / p >
< p > < strong > Class Methods:< / strong > < / p >
2018-11-27 16:10:17 +03:00
< pre > < code class = "php" > /**
* 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 = [])
< / code > < / pre >
2017-08-20 19:28:59 +03:00
< pre > < code class = "php" > /**
* This takes the ast of a schema document produced by the parse function in
* GraphQL\Language\Parser.
*
* If no schema definition is provided, then it will look for types named Query
* and Mutation.
*
* Given that AST it constructs a GraphQL\Type\Schema. The resulting schema
* has no resolve methods, so execution will use default resolvers.
*
2018-11-27 16:10:17 +03:00
* Accepts options as a third argument:
2018-04-20 12:39:52 +03:00
*
* - commentDescriptions:
* Provide true to use preceding comments as the description.
*
2018-11-27 16:10:17 +03:00
* @param bool[] $options
2018-04-20 12:39:52 +03:00
*
2017-08-20 19:28:59 +03:00
* @return Schema
2018-11-27 16:10:17 +03:00
*
2017-08-20 19:28:59 +03:00
* @throws Error
*
* @api
*/
2018-11-27 16:10:17 +03:00
static function buildAST(
GraphQL\Language\AST\DocumentNode $ast,
callable $typeConfigDecorator = null,
array $options = []
)
2017-08-20 19:28:59 +03:00
< / code > < / pre >
< h1 id = "graphqlutilsast" > GraphQL\Utils\AST< / h1 >
< p > Various utilities dealing with AST< / p >
< p > < strong > Class Methods:< / strong > < / p >
< pre > < code class = "php" > /**
* Convert representation of AST as an associative array to instance of GraphQL\Language\AST\Node.
*
* For example:
*
* ```php
2017-08-20 20:18:33 +03:00
* AST::fromArray([
2017-08-20 19:28:59 +03:00
* 'kind' => 'ListValue',
* 'values' => [
* ['kind' => 'StringValue', 'value' => 'my str'],
* ['kind' => 'StringValue', 'value' => 'my other str']
* ],
* 'loc' => ['start' => 21, 'end' => 25]
* ]);
* ```
*
* Will produce instance of `ListValueNode` where `values` prop is a lazily-evaluated `NodeList`
* returning instances of `StringValueNode` on access.
*
* This is a reverse operation for AST::toArray($node)
*
2018-11-27 16:10:17 +03:00
* @param mixed[] $node
*
2017-08-20 19:28:59 +03:00
* @api
*/
static function fromArray(array $node)
< / code > < / pre >
< pre > < code class = "php" > /**
* Convert AST node to serializable array
*
2018-11-27 16:10:17 +03:00
* @return mixed[]
*
2017-08-20 19:28:59 +03:00
* @api
*/
static function toArray(GraphQL\Language\AST\Node $node)
< / code > < / pre >
< pre > < code class = "php" > /**
* Produces a GraphQL Value AST given a PHP value.
*
* Optionally, a GraphQL type may be provided, which will be used to
* disambiguate between value primitives.
*
* | PHP Value | GraphQL Value |
* | ------------- | -------------------- |
* | Object | Input Object |
* | Assoc Array | Input Object |
* | Array | List |
* | Boolean | Boolean |
* | String | String / Enum Value |
* | Int | Int |
* | Float | Int / Float |
* | Mixed | Enum Value |
* | null | NullValue |
*
2018-11-27 16:10:17 +03:00
* @param Type|mixed|null $value
*
2017-08-20 19:28:59 +03:00
* @return ObjectValueNode|ListValueNode|BooleanValueNode|IntValueNode|FloatValueNode|EnumValueNode|StringValueNode|NullValueNode
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
static function astFromValue($value, GraphQL\Type\Definition\InputType $type)
< / code > < / pre >
< pre > < code class = "php" > /**
* Produces a PHP value given a GraphQL Value AST.
*
* A GraphQL type must be provided, which will be used to interpret different
* GraphQL Value literals.
*
* Returns `null` when the value could not be validly coerced according to
* the provided type.
*
* | GraphQL Value | PHP Value |
* | -------------------- | ------------- |
* | Input Object | Assoc Array |
* | List | Array |
* | Boolean | Boolean |
* | String | String |
* | Int / Float | Int / Float |
* | Enum Value | Mixed |
* | Null Value | null |
*
2018-11-27 16:10:17 +03:00
* @param ValueNode|null $valueNode
* @param mixed[]|null $variables
*
* @return mixed[]|stdClass|null
*
* @throws Exception
*
2017-08-20 19:28:59 +03:00
* @api
*/
2018-11-27 16:10:17 +03:00
static function valueFromAST($valueNode, GraphQL\Type\Definition\InputType $type, array $variables = null)
2017-08-20 19:28:59 +03:00
< / code > < / pre >
2018-04-20 12:39:52 +03:00
< pre > < code class = "php" > /**
* Produces a PHP value given a GraphQL Value AST.
*
2018-11-27 16:10:17 +03:00
* Unlike `valueFromAST()`, no type is provided. The resulting PHP value
2018-04-20 12:39:52 +03:00
* will reflect the provided GraphQL value AST.
*
* | GraphQL Value | PHP Value |
* | -------------------- | ------------- |
* | Input Object | Assoc Array |
* | List | Array |
* | Boolean | Boolean |
* | String | String |
* | Int / Float | Int / Float |
* | Enum | Mixed |
* | Null | null |
*
2018-11-27 16:10:17 +03:00
* @param Node $valueNode
* @param mixed[]|null $variables
*
2018-04-20 12:39:52 +03:00
* @return mixed
2018-11-27 16:10:17 +03:00
*
* @throws Exception
*
* @api
2018-04-20 12:39:52 +03:00
*/
static function valueFromASTUntyped($valueNode, array $variables = null)
< / code > < / pre >
2017-08-20 19:28:59 +03:00
< pre > < code class = "php" > /**
* Returns type definition for given AST Type node
*
* @param NamedTypeNode|ListTypeNode|NonNullTypeNode $inputTypeNode
2018-11-27 16:10:17 +03:00
*
* @return Type|null
*
* @throws Exception
*
* @api
2017-08-20 19:28:59 +03:00
*/
static function typeFromAST(GraphQL\Type\Schema $schema, $inputTypeNode)
< / code > < / pre >
< pre > < code class = "php" > /**
* Returns operation type (" query" , " mutation" or " subscription" ) given a document and operation name
*
* @param string $operationName
2018-11-27 16:10:17 +03:00
*
2017-08-20 19:28:59 +03:00
* @return bool
2018-11-27 16:10:17 +03:00
*
* @api
2017-08-20 19:28:59 +03:00
*/
static function getOperation(GraphQL\Language\AST\DocumentNode $document, $operationName = null)
< / code > < / pre >
< h1 id = "graphqlutilsschemaprinter" > GraphQL\Utils\SchemaPrinter< / h1 >
< p > Given an instance of Schema, prints it in GraphQL type language.< / p >
< p > < strong > Class Methods:< / strong > < / p >
< pre > < code class = "php" > /**
2018-04-20 12:39:52 +03:00
* Accepts options as a second argument:
*
* - commentDescriptions:
* Provide true to use preceding comments as the description.
2018-11-27 16:10:17 +03:00
*
* @param bool[] $options
*
2017-08-20 19:28:59 +03:00
* @api
*/
2018-04-20 12:39:52 +03:00
static function doPrint(GraphQL\Type\Schema $schema, array $options = [])
2017-08-20 19:28:59 +03:00
< / code > < / pre >
< pre > < code class = "php" > /**
2018-11-27 16:10:17 +03:00
* @param bool[] $options
*
2017-08-20 19:28:59 +03:00
* @api
*/
2018-11-27 16:10:17 +03:00
static function printIntrospectionSchema(GraphQL\Type\Schema $schema, array $options = [])
2017-08-20 19:28:59 +03:00
< / code > < / pre >
< / div >
< / div >
< footer >
< div class = "rst-footer-buttons" role = "navigation" aria-label = "footer navigation" >
< a href = "../how-it-works/" class = "btn btn-neutral" title = "How it works" > < span class = "icon icon-circle-arrow-left" > < / span > Previous< / a >
< / div >
< hr / >
< div role = "contentinfo" >
<!-- Copyright etc -->
< / div >
Built with < a href = "http://www.mkdocs.org" > MkDocs< / a > using a < a href = "https://github.com/snide/sphinx_rtd_theme" > theme< / a > provided by < a href = "https://readthedocs.org" > Read the Docs< / a > .
< / footer >
2018-04-20 12:39:52 +03:00
2017-08-20 19:28:59 +03:00
< / div >
< / div >
< / section >
2018-04-20 12:39:52 +03:00
2017-08-20 19:28:59 +03:00
< / div >
< div class = "rst-versions" role = "note" style = "cursor: pointer" >
< span class = "rst-current-version" data-toggle = "rst-current-version" >
< span > < a href = "../how-it-works/" style = "color: #fcfcfc;" > « Previous< / a > < / span >
< / span >
< / div >
2018-04-20 12:39:52 +03:00
< script > var base _url = '..' ; < / script >
2018-11-27 16:06:49 +03:00
< script src = "../js/theme.js" defer > < / script >
< script src = "../search/main.js" defer > < / script >
2017-08-20 19:28:59 +03:00
< / body >
< / html >