
<a name="graphqlgraphql"></a>
# GraphQL\GraphQL
这是实现 GraphQL 操作的主要 Facade 方法。
参见 [相关文档](https://laravel-china.org/docs/graphql-php/executing-queries).

**类方法：** 
```php
/**
 * 执行 graphql 查询。
 *
 * 更复杂的 GraphQL 服务器，比如那些持久化查询可能希望将验证和执行阶段分离
 * 为静态时间工具步骤和服务器运行时步骤
 * 
 * 可用选项：
 *
 * 模式:
 *    验证和执行查询时使用 GraphQL 类型。
 * 源代码:
 *    GraphQL 语言格式的字符串，表示请求的操作。
 * rootValue:
 *    作为顶部解析器功能的第一个参数提供的值
 *    级别类型 (例如：查询对象类型)。
 * 上下文:
 *    作为所有解析器的第三个参数提供的值
 *    使用它来传递当前会话，用户数据等
 * variableValues:
 *    变量名到运行时值的映射，以用于所有变量
 *    在 requestString 中定义
 * operationName:
 *    如果包含多个 requestString，则使用的操作名称可能的操作。
 *    如果仅包含 requestString，则可以省略一次操作。
 * fieldResolver:
 *    模式未提供解析器功能时使用的解析器功能。
 *    如果未提供，则使用默认的字段解析器（查找带有字段名称的源值上的值）
 * validationRules:
 *    一组用于查询验证步骤的规则。默认值为所有可用规则。
 *    空数组将允许跳过查询验证（对于持久化可能很方便在持久化之前已验证并在执行期间被视为有效的查询）
 *
 * @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
 *
 * @return ExecutionResult
 */
static function executeQuery(
    GraphQL\Type\Schema $schema,
    $source,
    $rootValue = null,
    $context = null,
    $variableValues = null,
    $operationName = null,
    callable $fieldResolver = null,
    array $validationRules = null
)
```




```php
/**
 * 与 executeQuery() 一样，但需要 PromiseAdapter 并始终返回 Promise。
 * 对异步 PHP 平台有用。
 *
 * @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
 *
 * @return Promise
 */
static function promiseToExecute(
    GraphQL\Executor\Promise\PromiseAdapter $promiseAdapter,
    GraphQL\Type\Schema $schema,
    $source,
    $rootValue = null,
    $context = null,
    $variableValues = null,
    $operationName = null,
    callable $fieldResolver = null,
    array $validationRules = null
)
```

```php
/**
 * 返回 GraphQL 规范中定义的指令
 *
 * @api
 * @return Directive[]
 */
static function getStandardDirectives()
```

```php
/**
 * 返回 GraphQL 规范中定义的类型
 *
 * @api
 * @return Type[]
 */
static function getStandardTypes()
```

```php
/**
 * 返回实现 GraphQL 规范的标准验证规则
 *
 * @api
 * @return AbstractValidationRule[]
 */
static function getStandardValidationRules()
```


<a name="graphql-type-definition-type"></a>
# GraphQL\Type\Definition\Type
标准 GraphQL 类型的注册表
以及所有其他类型的基类。

**方法类:** 
```php
/**
 * @api
 * @返回 ID 类型
 */
static function id()
```

```php
/**
 * @api
 * @返回 String 类型
 */
static function string()
```

```php
/**
 * @api
 * @返回 Boolean 类型
 */
static function boolean()
```

```php
/**
 * @api
 * @返回 Int 类型
 */
static function int()
```

```php
/**
 * @api
 * @返回 Float 类型
 */
static function float()
```

```php
/**
 * @api
 * @参数
 *  类型 | 对象类型 | 接口类型 | 联合类型 | 标量类型 | 输入对象类型 | 枚举类型 | 列表类型 | 非空 $wrapped  Type
 * @返回 列表类型
 */
static function listOf($wrappedType)
```

```php
/**
 * @api
 * @参数 
 * 对象类型 | 接口类型 | 联合类型 | 标量类型 | 输入对象类型 | 枚举类型 | 列表类型 $wrapped Type
 * @返回 非空
 */
static function nonNull($wrappedType)
```

```php
/**
 * @api
 * @参数 Type $type
 * @返回 bool
 */
static function isInputType($type)
```

```php
/**
 * @api
 * @参数 Type $type
 * @返回 bool
 */
static function isOutputType($type)
```

```php
/**
 * @api
 * @参数 $type
 * @返回 bool
 */
static function isLeafType($type)
```

```php
/**
 * @api
 * @参数 Type $type
 * @返回 bool
 */
static function isCompositeType($type)
```

```php
/**
 * @api
 * @参数 Type $type
 * @返回 bool
 */
static function isAbstractType($type)
```

```php
/**
 * @api
 * @参数 Type $type
 * @返回 bool
 */
static function isType($type)
```

```php
/**
 * @api
 * @参数 Type $type
 * @返回  
 * 对象类型 | 接口类型 | 联合类型 | 标量类型 | 输入对象类型 | 枚举类型 | 列表类型
 */
static function getNullableType($type)
```

```php
/**
 * @api
 * @参数 Type $type
 * @返回  对象类型 | 接口类型 | 联合类型 | 标量类型 | 输入对象类型 | 枚举类型
 */
static function getNamedType($type)
```



<a name="graphql-type-definition-resolveinfo"></a>
# GraphQL\Type\Definition\ResolveInfo
结构体包含了用于字段解析的有用信息。它作为第三个参数传递给每个字段解析器。参见 [关于字段解析的文档 (data fetching)](https://laravel-china.org/docs/graphql-php/data-fetching).

**类道具:**
```php
/**
 * 被解析的字段名
 *
 * @api
 * @var string
 */
public $fieldName;

/**
 * 查询中引用该字段的所有节点的 AST。
 *
 * @api
 * @var FieldNode[]
 */
public $fieldNodes;

/**
 * 期望返回被解析字段的类型
 *
 * @api
 * @var ScalarType|ObjectType|InterfaceType|UnionType|EnumType|ListOfType|NonNull
 */
public $returnType;

/**
 * 被解析字段的父类型
 *
 * @api
 * @var ObjectType
 */
public $parentType;

/**
 * 从根值到字段的路径
 *
 * @api
 * @var array
 */
public $path;

/**
 * 用于执行的 Schema 的实例
 *
 * @api
 * @var Schema
 */
public $schema;

/**
 * 查询中定义所有片段的 AST
 *
 * @api
 * @var FragmentDefinitionNode[]
 */
public $fragments;

/**
 * 被传递到查询执行的根值
 *
 * @api
 * @var mixed
 */
public $rootValue;

/**
 * AST 操作定义节点(查询，突变)
 *
 * @api
 * @var OperationDefinitionNode
 */
public $operation;

/**
 * 被传递到查询执行的变量数组
 *
 * @api
 * @var array
 */
public $variableValues;
```




**类方法:**
```php
/**
 * Helper 方法，返回在查询 $this->fieldName 时选择的所有字段的名称，直到 $depth 层级。
 *
 * Example:
 * query MyQuery{
 * {
 *   root {
 *     id,
 *     nested {
 *      nested1
 *      nested2 {
 *        nested3
 *      }
 *     }
 *   }
 * }
 *
 * 给定此 ResolveInfo 实例是 "root" 字段解析的一部分，且 $depth === 1 时，方法将返回：
 * [
 *     'id' => true,
 *     'nested' => [
 *         nested1 => true,
 *         nested2 => true
 *     ]
 * ]
 *
 * 警告： 此方法是一个简单的实现，它不考虑条件类型片段，因此谨慎地使用接口和联合类型字段。
 *
 * @api
 * @param int $depth 输出中要包含多少层级
 * @return array
 */
function getFieldSelection($depth = 0)
```




# GraphQL\Language\DirectiveLocation
可用指令位置列表

**类常量：**
```php
const QUERY = "QUERY";
const MUTATION = "MUTATION";
const SUBSCRIPTION = "SUBSCRIPTION";
const FIELD = "FIELD";
const FRAGMENT_DEFINITION = "FRAGMENT_DEFINITION";
const FRAGMENT_SPREAD = "FRAGMENT_SPREAD";
const INLINE_FRAGMENT = "INLINE_FRAGMENT";
const SCHEMA = "SCHEMA";
const SCALAR = "SCALAR";
const OBJECT = "OBJECT";
const FIELD_DEFINITION = "FIELD_DEFINITION";
const ARGUMENT_DEFINITION = "ARGUMENT_DEFINITION";
const IFACE = "INTERFACE";
const UNION = "UNION";
const ENUM = "ENUM";
const ENUM_VALUE = "ENUM_VALUE";
const INPUT_OBJECT = "INPUT_OBJECT";
const INPUT_FIELD_DEFINITION = "INPUT_FIELD_DEFINITION";
```



<a name="graphql-type-schema-config"></a>
# GraphQL\Type\SchemaConfig
Schema 配置类。
可以直接传递给 schema 构造器。**创建** 方法接受的选项列表是
[在文档中描述](https://laravel-china.org/docs/graphql-php/type-system-schema#configuration-options).

使用实例：

    $config = SchemaConfig::create()
        ->setQuery($myQueryType)
        ->setTypeLoader($myTypeLoader);

    $schema = new Schema($config);

**类方法：**
```php
/**
 * 将选项数组转换为 SchemaConfig 的实例
 * (或仅在未传递数组时返回空配置)。
 *
 * @api
 * @param array $options
 * @return SchemaConfig
 */
static function create(array $options = [])
```

```php
/**
 * @api
 * @param ObjectType $query
 * @return SchemaConfig
 */
function setQuery($query)
```

```php
/**
 * @api
 * @param ObjectType $mutation
 * @return SchemaConfig
 */
function setMutation($mutation)
```

```php
/**
 * @api
 * @param ObjectType $subscription
 * @return SchemaConfig
 */
function setSubscription($subscription)
```

```php
/**
 * @api
 * @param Type[]|callable $types
 * @return SchemaConfig
 */
function setTypes($types)
```

```php
/**
 * @api
 * @param Directive[] $directives
 * @return SchemaConfig
 */
function setDirectives(array $directives)
```

```php
/**
 * @api
 * @param callable $typeLoader
 * @return SchemaConfig
 */
function setTypeLoader(callable $typeLoader)
```

```php
/**
 * @api
 * @return ObjectType
 */
function getQuery()
```

```php
/**
 * @api
 * @return ObjectType
 */
function getMutation()
```

```php
/**
 * @api
 * @return ObjectType
 */
function getSubscription()
```

```php
/**
 * @api
 * @return Type[]
 */
function getTypes()
```

```php
/**
 * @api
 * @return Directive[]
 */
function getDirectives()
```

```php
/**
 * @api
 * @return callable
 */
function getTypeLoader()
```



<a name="graphql-types-chema"></a>
<a name="graphqltypeschema"></a>
# GraphQL\Type\Schema
Schema 定义 (参见 [相关文档](https://laravel-china.org/docs/graphql-php/type-system-schema))

通过提供每个操作类型的根类型来创建 Schema:
查询，突变 (可选) 和订阅 (可选)。然后将 schema 定义提供给验证器和执行器。使用实例：

    $schema = new GraphQL\Type\Schema([
      'query' => $MyAppQueryRootType,
      'mutation' => $MyAppMutationRootType,
    ]);

或使用 Schema 配置实例：

    $config = GraphQL\Type\SchemaConfig::create()
        ->setQuery($MyAppQueryRootType)
        ->setMutation($MyAppMutationRootType);

    $schema = new GraphQL\Type\Schema($config);

**类方法：**
```php
/**
 * Schema 构造器。
 *
 * @api
 * @param array|SchemaConfig $config
 */
function __construct($config)
```

```php
/**
 * 返回 schema 查询类型
 *
 * @api
 * @return ObjectType
 */
function getQueryType()
```

```php
/**
 * 返回 schema 转变类型
 *
 * @api
 * @return ObjectType|null
 */
function getMutationType()
```

```php
/**
 * 返回 schema 订阅
 *
 * @api
 * @return ObjectType|null
 */
function getSubscriptionType()
```

```php
/**
 * @api
 * @return SchemaConfig
 */
function getConfig()
```

```php
/**
 * 在 schema 返回所有类型数组。数组的键值代表类型名称，值为对应的类型定义实例
 *
 * This operation requires full schema scan. Do not use in production environment.
 *
 * @api
 * @return Type[]
 */
function getTypeMap()
```

```php
/**
 * 按名称返回类型
 *
 * @api
 * @param string $name
 * @return Type
 */
function getType($name)
```

```php
/**
 * 返回给定抽象类型所有可能具体类型
 * (实现接口并且联合成员类型)
 *
 * 此操作请求是全 schema 扫描。不要在生产环境中使用
 *
 * @api
 * @param AbstractType $abstractType
 * @return ObjectType[]
 */
function getPossibleTypes(GraphQL\Type\Definition\AbstractType $abstractType)
```

```php
/**
 * 如果对象类型是给定抽象类型的具体类型返回
 * (实现接口并且联合成员类型)
 *
 * @api
 * @param AbstractType $abstractType
 * @param ObjectType $possibleType
 * @return bool
 */
function isPossibleType(
    GraphQL\Type\Definition\AbstractType $abstractType,
    GraphQL\Type\Definition\ObjectType $possibleType
)
```

```php
/**
 *  通过 schema 返回支持的指令列表
 *
 * @api
 * @return Directive[]
 */
function getDirectives()
```

```php
/**
 * 通过名称返回指令实例
 *
 * @api
 * @param $name
 * @return Directive
 */
function getDirective($name)
```

```php
/**
 * 验证 schema。
 *
 * 此操作请求是全 schema 扫描。不要在生产环境中使用
 *
 * @api
 * @return InvariantViolation[]|Error[]
 */
function validate()
```

```php
/**
 * 验证 schema.
 *
 * 此操作请求是全 schema 扫描。不要在生产环境中使用
 *
 * @api
 * @throws InvariantViolation
 */
function assertValid()
```



# GraphQL\Language\Parser
解析包含 GraphQL 请求的字符串或 [类型定义](https://laravel-china.org/docs/graphql-php/type-system-type-language) 到抽象语法树。

**类方法:**
```php
/**
 * 给定 GraphQL 源，将它解析到 `GraphQL\Language\AST\DocumentNode`。
 * 如果遇到解析错误，抛出 `GraphQL\Error\SyntaxError` 异常。
 *
 * 可用选项：
 *
 * noLocation: boolean,
 * (默认情况，解析创建知道它们在源代码中位置的 AST 节点。
 * 此 配置标志将禁用性能测试的行为。）
 *
 * experimentalFragmentVariables: boolean,
 * (如果启用，解析器将理解并解析包含在片段定义中的变量定义。
 * 它们将在 FragmentDefinitionNode 的 `variableDefinitions` 的字段中表示。
 *
 * 语法与普通的查询定义变量相同。例如：
 *
 *   fragment A($var: Boolean = false) on T  {
 *     ...
 *   }
 *
 * 注意: 此特性是试验性的，以后可能会更改或删除。）
 *
 * @api
 * @param Source|string $source
 * @param array $options
 * @return DocumentNode
 * @throws SyntaxError
 */
static function parse($source, array $options = [])
```



```php
/**
 * 给定包含 GraphQL 值的字符串 (例如。 `[42]`)，解析该值的 AST。
 * 如果遇到解析错误，将抛出 `GraphQL\Error\SyntaxError` 。
 *
 * 这在直接对 GraphQL 值进行操作的工具中非常有用，并与完整的 GraphQL 文档隔离。
 *
 * 考虑将结果提供给有效用的函数： `GraphQL\Utils\AST::valueFromAST()`。
 *
 * @api
 * @param Source|string $source
 * @param array $options
 * @return BooleanValueNode|EnumValueNode|FloatValueNode|IntValueNode|ListValueNode|ObjectValueNode|StringValueNode|VariableNode
 */
static function parseValue($source, array $options = [])
```




```php
/**
 * 给定包含 GraphQL 值的字符串 (例如。`[Int!]`)，解析该值的 AST。
 * 如果遇到解析错误，将抛出 `GraphQL\Error\SyntaxError` 。
 *
 * 这在直接对 GraphQL 值进行操作的工具中非常有用，并与完整的 GraphQL 文档隔离。
 *
 * 考虑将结果提供给有效用的函数 `GraphQL\Utils\AST::valueFromAST()`。
 *
 * @api
 * @param Source|string $source
 * @param array $options
 * @return ListTypeNode|NameNode|NonNullTypeNode
 */
static function parseType($source, array $options = [])
```




# GraphQL\Language\Printer
将 AST 打印为字符串。能够打印 GraphQL 查询和类型定义语言。
用于打印查询或打印回 AST 以用日志、文档等。

用法示例：

```php
$query = 'query myQuery {someField}';
$ast = GraphQL\Language\Parser::parse($query);
$printed = GraphQL\Language\Printer::doPrint($ast);
```

**类方法：**
```php
/**
 * Prints AST to string. Capable of printing GraphQL queries and Type definition language.
 *
 * @api
 * @param Node $ast
 * @return string
 */
static function doPrint($ast)
```



<a name="graphqllanguagevisitor"></a>
# GraphQL\Language\Visitor
用以高效遍历和修改 AST 的实用程序。

`visit()` 将使用深度优先遍历 AST，在遍历中的每个节点调用访问者的 enter 函数，并在访问该节点及其所有子节点后调用 leave 函数。

通过从 enter 和 leave 函数返回不同的值，可以改变访问者的行为， 包括跳过 AST 的一个子树(返回 false)，通过返回值编辑 AST，或通过返回 null 删除值，或通过返回 BREAK 停止整个遍历。

当使用 `visit()` 编辑 AST 时，原始 AST 不会被修改，visit 函数将返回一个新版本的 AST 及其应用的更改。

    $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
      }
    ]);



或者提供 enter() 和 leave() 函数，还可以提供与 [AST 节点的种类](#graphqllanguageastnodekind)，或者 enter/leave 访问者的命名键相同的函数，导致访问者 API 的四种排列：

1) 进入某个节点时触发的命名访问者。

    Visitor::visit($ast, [
      'Kind' => function ($node) {
        // enter the "Kind" node
      }
    ]);

2) 指定进入和离开
特定类型的节点时触发的访问者。

    Visitor::visit($ast, [
      'Kind' => [
        'enter' => function ($node) {
          // enter the "Kind" node
        }
        'leave' => function ($node) {
          // leave the "Kind" node
        }
      ]
    ]);

3) 进入和离开任何节点时触发的一般访问者。

    Visitor::visit($ast, [
      'enter' => function ($node) {
        // enter any node
      },
      'leave' => function ($node) {
        // leave any node
      }
    ]);

4) 进入和离开特定类型节点的并行访问者。

    Visitor::visit($ast, [
      'enter' => [
        'Kind' => function($node) {
          // enter the "Kind" node
        }
      },
      'leave' => [
        'Kind' => function ($node) {
          // leave the "Kind" node
        }
      ]
    ]);




**类方法**
```php
/**
 * 访问 AST (详细信息请参见类描述)
 *
 * @api
 * @param Node $root
 * @param array $visitor
 * @param array $keyMap
 * @return Node|mixed
 * @throws \Exception
 */
static function visit($root, $visitor, $keyMap = null)
```

```php
/**
 * 返回访问者中断标记
 *
 * @api
 * @return VisitorOperation
 */
static function stop()
```

```php
/**
 * 返回跳过当前节点的标记
 *
 * @api
 * @return VisitorOperation
 */
static function skipNode()
```

```php
/**
 * 返回删除节点的标记
 *
 * @api
 * @return VisitorOperation
 */
static function removeNode()
```



<a name="graphqllanguageastnodekind"></a>
# GraphQL\Language\AST\NodeKind

**类常量：**
```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";
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";
const DIRECTIVE_DEFINITION = "DirectiveDefinition";
```




# GraphQL\Executor\Executor
实现 GraphQL 规范的 "评估请求" 部分。
**类方法：**
```php
/**
 * 根据给定的 $schema 执行 DocumentNode。
 *
 * 始终返回 ExecutionResult，从不抛出。操作过程中发生的所有错误
 * 都收集在` `$result->errors`.
 *
 * @api
 * @param Schema $schema
 * @param DocumentNode $ast
 * @param $rootValue
 * @param $contextValue
 * @param array|\ArrayAccess $variableValues
 * @param null $operationName
 * @param callable $fieldResolver
 *
 * @return ExecutionResult|Promise
 */
static function execute(
    GraphQL\Type\Schema $schema,
    GraphQL\Language\AST\DocumentNode $ast,
    $rootValue = null,
    $contextValue = null,
    $variableValues = null,
    $operationName = null,
    callable $fieldResolver = null
)
```




```php
/**
 * 与 execute() 相同，但需要 promise 适配器并返回一个 promise 该 promise 总是通过ExecutionResult的实例来实现，并且从不被拒绝
 *
 * 适用于异步PHP平台。
 *
 * @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
 * @return Promise
 */
static function promiseToExecute(
    GraphQL\Executor\Promise\PromiseAdapter $promiseAdapter,
    GraphQL\Type\Schema $schema,
    GraphQL\Language\AST\DocumentNode $ast,
    $rootValue = null,
    $contextValue = null,
    $variableValues = null,
    $operationName = null,
    callable $fieldResolver = null
)
```



<a name="graphqlexecutorexecutionresult"></a>
# GraphQL\Executor\ExecutionResult
在 [查询执行](https://laravel-china.org/docs/graphql-php/executing-queries) 之后返回。
代表成功执行和失败的结果。
(在 `错误` prop 中收集错误)

可以使用 `toArray()` 转换为序列化数组 [spec-compliant](https://facebook.github.io/graphql/#sec-Response-Format)

**类 Props:**
```php
/**
 * 查询执行过程中从解析器收集的数据
 *
 * @api
 * @var array
 */
public $data;

/**
 * 查询执行过程中注册了错误。
 *
 * 如果错误是由解析器抛出异常引起的，$error->getPrevious()
 * 包含原始的异常。
 *
 * @api
 * @var \GraphQL\Error\Error[]
 */
public $errors;

/**
 * 序列化结果中包含用户定义的可序列化扩展数组。
 * 
 *
 * @api
 * @var array
 */
public $extensions;
```

**类方法：**
```php
/**
 * 定义自定义的错误格式 (必须符合 http://facebook.github.io/graphql/#sec-Errors）
 *
 * 预期的签名是：function (GraphQL\Error\Error $error): array
 *
 * 错误格式是 "GraphQL\Error\FormattedError::createFromException"
 *
 * 预期返回值必须是数组：
 * array(
 *    'message' => 'errorMessage',
 *    // ... other keys
 * );
 *
 * @api
 * @param callable $errorFormatter
 * @return $this
 */
function setErrorFormatter(callable $errorFormatter)
```





```php
/**
 * 定义错误处理(过滤、记录等) 的自定义逻辑
 *
 * 预期的处理程序签名是： function (array $errors, callable $formatter): array
 *
 * 默认处理程序是：
 * function (array $errors, callable $formatter) {
 *     return array_map($formatter, $errors);
 * }
 *
 * @api
 * @param callable $handler
 * @return $this
 */
function setErrorsHandler(callable $handler)
```

```php
/**
 * 使用错误和格式化程序将 GraphQL 查询结果转换为符合规范的可序列化数组。  
 *
 * 如果传入了调试参数，则错误输出格式化程序的输出将丰富调试信息 
 * ("调试消息"， "追踪" 键取决于标志)。
 *
 * $debug 参数必须是 bool (值在结果中添加 "调试消息") 或来自
 * GraphQL\Error\Debug
 *
 * @api
 * @param bool|int $debug
 * @return array
 */
function toArray($debug = false)
```



<a name="graphqlexecutorpromisepromiseadapter"></a>
# GraphQL\Executor\Promise\PromiseAdapter
提供了一种集成异步 PHP 平台的方法 ([相关文档](https://laravel-china.org/docs/graphql-php/data-fetching#async-php))

**接口方法:**
```php
/**
 * 如果值是底层平台的 promise 或 deferred，则返回 true。
 *
 * @api
 * @param mixed $value
 * @return bool
 */
function isThenable($value)
```




```php
/**
 * 将底层平台的表转换为 GraphQL\Executor\Promise\Promise 实例
 *
 * @api
 * @param object $thenable
 * @return Promise
 */
function convertThenable($thenable)
```

```php
/**
 * 接受我们的 Promise 包装，从中提取接受的 promise 并执行实际的  `then`，然后执行 Promises/A+ 规范中的描述。
 * 然后返回新的 GraphQL\Executor\Promise\Promise 包装实例。
 *
 * @api
 * @param Promise $promise
 * @param callable|null $onFulfilled
 * @param callable|null $onRejected
 *
 * @return Promise
 */
function then(
    GraphQL\Executor\Promise\Promise $promise,
    callable $onFulfilled = null,
    callable $onRejected = null
)
```




```php
/**
 * 创建 Promise
 * 预期的解析器签名：
 *     function(callable $resolve, callable $reject)
 *
 * @api
 * @param callable $resolver
 * @return Promise
 */
function create(callable $resolver)
```

```php
/**
 * 如果值不是 promise 则为值创造一个实现的 promise。
 *
 * @api
 * @param mixed $value
 * @return Promise
 */
function createFulfilled($value = null)
```

```php
/**
 * 如果原因不是 promise，则创建拒绝 promise 的原因。如果原因是
 * promise，则按原样返回。
 *
 * @api
 * @param \Throwable $reason
 * @return Promise
 */
function createRejected($reason)
```

```php
/**
 * 给定的一个 promises (或值) 数组，当数组中所有条目被实现，返回一个实现的 promise。
 *
 * @api
 * @param array $promisesOrValues Promises or values.
 * @return Promise
 */
function all(array $promisesOrValues)
```



# GraphQL\Validator\DocumentValidator
实现规范的 "验证" 部分。

验证同步运行，返回遇到错误的数组，如果没有错误且文档有效返回一个空数组。

可提供特定验证规则的列表。如果未提供，将使用 GraphQL 规范默认定义的默认规则列表。

每一个验证规则都是 GraphQL\Validator\Rules\AbstractValidationRule 的一个实例，它返回一个访问者 (参见 [GraphQL\Language\Visitor API](#graphqllanguagevisitor)).

访问者方法应返回 [GraphQL\Error\Error](#graphqlerrorerror) 实例，或在无效时返回此类实例的数组。

可选地，可以提供自定义的 TypeInfo 实例。如果未提供，将根据提供的 schema 创建一个。




**类方法：**
```php
/**
 * 查询验证主要的方法。有关详细信息，请参见类描述。
 *
 * @api
 * @param Schema $schema
 * @param DocumentNode $ast
 * @param AbstractValidationRule[]|null $rules
 * @param TypeInfo|null $typeInfo
 * @return Error[]
 */
static function validate(
    GraphQL\Type\Schema $schema,
    GraphQL\Language\AST\DocumentNode $ast,
    array $rules = null,
    GraphQL\Utils\TypeInfo $typeInfo = null
)
```

```php
/**
 * 返回所有全局验证规则。
 *
 * @api
 * @return AbstractValidationRule[]
 */
static function allRules()
```




```php
/**
 * 按名称返回全局验证规则。标准规则是按类名命名的，因此这类规则的示例用法是：
 *
 * $rule = DocumentValidator::getRule(GraphQL\Validator\Rules\QueryComplexity::class);
 *
 * @api
 * @param string $name
 * @return AbstractValidationRule
 */
static function getRule($name)
```

```php
/**
 * 将规则添加到全局验证规则列表
 *
 * @api
 * @param AbstractValidationRule $rule
 */
static function addRule(GraphQL\Validator\Rules\AbstractValidationRule $rule)
```



<a name="graphqlerrorerror"></a>
# GraphQL\Error\Error
描述在执行 GraphQL 操作的解析、验证或执行阶段发现的错误。除了消息和堆栈跟踪之外，它还包括有关 GraphQL 文档中的位置 and/or 与错误对应执行结果的信息。

当错误是由解析器中报出异常引起的，原始异常可通过 `getPrevious()` 获得。

还可以阅读相关文档 [错误处理](https://laravel-china.org/docs/graphql-php/error-handling)

类扩展了标准 PHP `\Exception`，因此除了下面列出的方法之外，基类 `\Exception` 的所有标准方法都可用。

**类常量：**
```php
const CATEGORY_GRAPHQL = "graphql";
const CATEGORY_INTERNAL = "internal";
```




**类方法：**
```php
/**
 * 源 GraphQL 文档中与此错误对应的位置数组。
 *
 * 每个条目都有关于源 GraphQL 文档中 `line` 和 `column` 的信息：
 * $location->line;
 * $location->column;
 *
 * 验证期间的错误通常包含多个位置， 例如指向多个片段中提到的字段。
 * 执行期间的错误包括一个单一位置，即产生错误的字段。
 *
 * @api
 * @return SourceLocation[]
 */
function getLocations()
```




```php
/**
 * 返回一个数组，描述从根值到产生此错误的字段的路径。
 * 仅包括执行错误。
 *
 * @api
 * @return array|null
 */
function getPath()
```




# GraphQL\Error\Warning
封装了库生成的警告。

如果需要，可以抑制 (单独或全部) 警告。
还可以覆盖警告处理默认程序 (默认情况下为 **trigger_error()**)

**类常量：**
```php
const WARNING_ASSIGN = 2;
const WARNING_CONFIG = 4;
const WARNING_FULL_SCHEMA_SCAN = 8;
const WARNING_CONFIG_DEPRECATION = 16;
const WARNING_NOT_A_TYPE = 32;
const ALL = 63;
```




**类方法：**
```php
/**
 * 设置可以拦截设置可以拦截所有系统警告的警告处理程序。
 * 未设置时，触发器 _error() 用于通知警告.
 *
 * @api
 * @param callable|null $warningHandler
 */
static function setWarningHandler(callable $warningHandler = null)
```

```php
/**
 * 按 id 抑制警告(设置自定义警告处理程序时无效)
 *
 * 用法示例：
 * Warning::suppress(Warning::WARNING_NOT_A_TYPE)
 *
 * When passing true - suppresses all warnings.
 *
 * @api
 * @param bool|int $suppress
 */
static function suppress($suppress = true)
```




```php
/**
 * 重新启用以前按 id 抑制的警告
 *
 * 用法示例：
 * Warning::suppress(Warning::WARNING_NOT_A_TYPE)
 *
 *当传递true时，重新启用所有警告
 *
 * @api
 * @param bool|int $enable
 */
static function enable($enable = true)
```



<a name="graphqlerrorclientaware"></a>
# GraphQL\Error\ClientAware
此接口用于 [默认错误格式](https://laravel-china.org/docs/graphql-php/error-handling).

只有实现此接口的错误 (并从 `isClientSafe()` 返回 true)
才会使用原始错误消息格式化。

所有其他错误将被格式化为通用的『内部服务器错误』

**接口方法：**
```php
/**
 * 当异常消息可以安全地显示给客户端时，返回 true 。
 *
 * @api
 * @return bool
 */
function isClientSafe()
```




```php
/**
 * 返回描述错误类别的字符串。
 *
 * 值『graphql』 是为查询解析或验证产生的错误保留的，不要使用它。
 *
 * @api
 * @return string
 */
function getCategory()
```



# GraphQL\Error\Debug
为 [error debugging](https://laravel-china.org/docs/graphql-php/error-handling#debugging-tools) 收集标志。

**类常量：**
```php
const INCLUDE_DEBUG_MESSAGE = 1;
const INCLUDE_TRACE = 2;
const RETHROW_INTERNAL_EXCEPTIONS = 4;
```

# GraphQL\Error\FormattedError
此类用于 [默认错误格式](https://laravel-china.org/docs/graphql-php/error-handling)。
它将PHP异常转换为[符合规范的错误](https://facebook.github.io/graphql/#sec-Errors) 并提供错误调试工具。




**类方法：**
```php
/**
 * 设置使用 createFormattedError() 格式化内部错误的默认错误消息。
 * 可以通过向 `createFormattedError()` 传入三个参数来覆盖该值。
 *
 * @api
 * @param string $msg
 */
static function setInternalErrorMessage($msg)
```

```php
/**
 * 标准 GraphQL 错误格式。将任何异常转换为符合 GraphQL 规范的数组。
 *
 * 此方法仅在异常实现了 ClientAware 接口*(或传递调试标志时)时才公开异常消息。
 *
 * 有关可用调试标志的列表，请参阅GraphQL\Error\Debug常量。
 *
 * @api
 * @param \Throwable $e
 * @param bool|int $debug
 * @param string $internalErrorMessage
 * @return array
 * @throws \Throwable
 */
static function createFromException($e, $debug = false, $internalErrorMessage = null)
```

```php
/**
 * 返回错误跟踪作为可序列化数组
 *
 * @api
 * @param \Throwable $error
 * @return array
 */
static function toSafeTrace($error)
```



# GraphQL\Server\StandardServer
GraphQL server 都与两者兼容： [express-graphql](https://github.com/graphql/express-graphql)
and [Apollo Server](https://github.com/apollographql/graphql-server).
用法示例：

    $server = new StandardServer([
      'schema' => $mySchema
    ]);
    $server->handleRequest();

或使用 [ServerConfig](#graphqlserverserverconfig) 实例：

    $config = GraphQL\Server\ServerConfig::create()
        ->setSchema($mySchema)
        ->setContext($myContext);

    $server = new GraphQL\Server\StandardServer($config);
    $server->handleRequest();

详细内容请参见 [dedicated section in docs](https://laravel-china.org/docs/graphql-php/executing-queries#using-server) 。




**类方法：**
```php
/**
 * 将和异常转换为错误并发送符合规范的 500 错误。
 * 当异常在服务器执行上下文之外引发时，非常有用。
 * (e.g. 在 schema 实例化期间)。
 *
 * @api
 * @param \Throwable $error
 * @param bool $debug
 * @param bool $exitWhenDone
 */
static function send500Error($error, $debug = false, $exitWhenDone = false)
```

```php
/**
 * 创建标准 GraphQL HTTP 服务器的新实例
 *
 * @api
 * @param ServerConfig|array $config
 */
function __construct($config)
```




```php
/**
 * 解析 HTTP 请求，执行并发出响应 (使用标准的 PHP `header` 和  `echo` 函数)
 *
 * 默认情况下 (未设置 $parsedBody)，它使用 PHP 全局函数去解析请求。
 * 可以在其他地方执行请求解析(e.g. 使用框架请求实例)。
 *
 * 如果你更想自己去发出响应，参见 `executeRequest()`。
 * (e.g. 使用某个框架的响应对象)
 *
 * @api
 * @param OperationParams|OperationParams[] $parsedBody
 * @param bool $exitWhenDone
 */
function handleRequest($parsedBody = null, $exitWhenDone = false)
```




```php
/**
 * 执行 GraphQL 操作并返回执行结果。
 * （或当 promise adapter 与 SyncPromiseAdapter 不同时返回 promise）。
 *
 * 默认情况下 (当 $parsedBody 未设置) 它使用 PHP 全局变量来解析请求。
 * 可以在其他地方执行请求解析 (e.g. 使用框架请求实例)
 * 然后将其传递给服务器。
 *
 * PSR-7 compatible method executePsrRequest() does exactly this.
 *
 * @api
 * @param OperationParams|OperationParams[] $parsedBody
 * @return ExecutionResult|ExecutionResult[]|Promise
 * @throws InvariantViolation
 */
function executeRequest($parsedBody = null)
```




```php
/**
 * 执行 PSR-7 请求并完成 PSR-7 响应。
 *
 * 如果您希望自己创建响应，参见 `executePsrRequest()` 。
 * (e.g. 使用某些框架的特定 JsonResponse 实例)。
 *
 * @api
 * @param ServerRequestInterface $request
 * @param ResponseInterface $response
 * @param StreamInterface $writableBodyStream
 * @return ResponseInterface|Promise
 */
function processPsrRequest(
    Psr\Http\Message\ServerRequestInterface $request,
    Psr\Http\Message\ResponseInterface $response,
    Psr\Http\Message\StreamInterface $writableBodyStream
)
```

```php
/**
 * 执行 GraphQL 操作并返回执行结果
 * (或 promiseAdapter 与 SyncPromiseAdapter 不同时的promiseAdapter)
 *
 * @api
 * @param ServerRequestInterface $request
 * @return ExecutionResult|ExecutionResult[]|Promise
 */
function executePsrRequest(Psr\Http\Message\ServerRequestInterface $request)
```




```php
/**
 * 返回一个服务器助手实例，其中包含解析/验证/执行请求 which (可以被其他服务器实现重用) 的大部分实际逻辑。
 *
 * @api
 * @return Helper
 */
function getHelper()
```



<a name="graphqlserverserverconfig"></a>
# GraphQL\Server\ServerConfig
服务器配置类。
可以直接传递给服务器构造函数。 **Create** 方法接受的选项列表为
[文档描述](https://laravel-china.org/docs/graphql-php/executing-queries#server-configuration-options).

使用示例：

    $config = GraphQL\Server\ServerConfig::create()
        ->setSchema($mySchema)
        ->setContext($myContext);

    $server = new GraphQL\Server\StandardServer($config);

**类方法：**
```php
/**
 * 将选项数组转换为 ServerConfig 的实例
 * ( 或者在未传递数组时仅返回空的配置 )。
 *
 * @api
 * @param array $config
 * @return ServerConfig
 */
static function create(array $config = [])
```




```php
/**
 * @api
 * @param Schema $schema
 * @return $this
 */
function setSchema(GraphQL\Type\Schema $schema)
```

```php
/**
 * @api
 * @param mixed|\Closure $context
 * @return $this
 */
function setContext($context)
```

```php
/**
 * @api
 * @param mixed|\Closure $rootValue
 * @return $this
 */
function setRootValue($rootValue)
```

```php
/**
 * Expects function(Throwable $e) : array
 *
 * @api
 * @param callable $errorFormatter
 * @return $this
 */
function setErrorFormatter(callable $errorFormatter)
```

```php
/**
 * Expects function(array $errors, callable $formatter) : array
 *
 * @api
 * @param callable $handler
 * @return $this
 */
function setErrorsHandler(callable $handler)
```

```php
/**
 * Set validation rules for this server.
 *
 * @api
 * @param array|callable
 * @return $this
 */
function setValidationRules($validationRules)
```

```php
/**
 * @api
 * @param callable $fieldResolver
 * @return $this
 */
function setFieldResolver(callable $fieldResolver)
```

```php
/**
 * Expects function($queryId, OperationParams $params) : string|DocumentNode
 *
 * 此函数必须返回查询字符串或有效的 DocumentNode。
 *
 * @api
 * @param callable $persistentQueryLoader
 * @return $this
 */
function setPersistentQueryLoader(callable $persistentQueryLoader)
```





```php
/**
 * 设置响应调试标志。有关所有可用标志的列表，请参见 GraphQL\Error\Debug。
 *
 * @api
 * @param bool|int $set
 * @return $this
 */
function setDebug($set = true)
```

```php
/**
 * 允许批处理查询 (默认禁用)
 *
 * @api
 * @param bool $enableBatching
 * @return $this
 */
function setQueryBatching($enableBatching)
```

```php
/**
 * @api
 * @param PromiseAdapter $promiseAdapter
 * @return $this
 */
function setPromiseAdapter(GraphQL\Executor\Promise\PromiseAdapter $promiseAdapter)
```




# GraphQL\Server\Helper
包含可由各种服务器实现重复使用的功能

**类方法：**
```php
/**
 * 使用php全局变量解析HTTP请求，并返回此请求中包含的GraphQL操作参数。对于批处理请求，它返回一个OperationParams数组
 *
 * 此函数不检查这些参数的有效性(验证在 validateOperationParams() 方法中单独执行)。
 *
 *如果未提供 $readRawBodyFn 参数，将尝试从`php://input`流在内部，它将输入规范化为$method、$bodyParams和$queryParams，并调用`parseRequestParams()`以生成实际返回值
 * 并调用 `parseRequestParams()` 以生成实际返回值。
 *
 * 对于 PSR-7 请求解析，请改用 `parsePsrRequest()`。
 *
 * @api
 * @param callable|null $readRawBodyFn
 * @return OperationParams|OperationParams[]
 * @throws RequestError
 */
function parseHttpRequest(callable $readRawBodyFn = null)
```




```php
/**
 * 解析规范化的请求参数，并在批处理操作时返回 OperationParams 的实例或OperationParams的数组。
 *
 *返回值是`执行操作`或 `执行包` (如果数组)
 *
 * @api
 * @param string $method
 * @param array $bodyParams
 * @param array $queryParams
 * @return OperationParams|OperationParams[]
 * @throws RequestError
 */
function parseRequestParams($method, array $bodyParams, array $queryParams)
```

```php
/**
 * 检查从HTTP请求中提取的操作参数的有效性，并返回一个错误数组，如果参数无效 (或参数有效时为空数组)。
 *
 * @api
 * @param OperationParams $params
 * @return Error[]
 */
function validateOperationParams(GraphQL\Server\OperationParams $params)
```




```php
/**
 * 使用给定的服务器配置执行 GraphQL 操作，并返回执行结果
 * (当 promise 适配器与 SyncPromiseAdapter 不同时，返回 promise)
 *
 * @api
 * @param ServerConfig $config
 * @param OperationParams $op
 *
 * @return ExecutionResult|Promise
 */
function executeOperation(GraphQL\Server\ServerConfig $config, GraphQL\Server\OperationParams $op)
```

```php
/**
 * 使用共享 promise 队列执行批量 GraphQL 操作
 * (因此，有效地一次批处理延迟了所有查询的 promise)
 *
 * @api
 * @param ServerConfig $config
 * @param OperationParams[] $operations
 * @return ExecutionResult[]|Promise
 */
function executeBatch(GraphQL\Server\ServerConfig $config, array $operations)
```




```php
/**
 * 使用标准的 PHP `header()` 和 `echo` 发送响应。
 *
 * @api
 * @param Promise|ExecutionResult|ExecutionResult[] $result
 * @param bool $exitWhenDone
 */
function sendResponse($result, $exitWhenDone = false)
```

```php
/**
 * 将 PSR-7 转换为 OperationParams[]
 *
 * @api
 * @param ServerRequestInterface $request
 * @return array|Helper
 * @throws RequestError
 */
function parsePsrRequest(Psr\Http\Message\ServerRequestInterface $request)
```




```php
/**
 * 转换查询执行结果为 PSR-7 响应
 *
 * @api
 * @param Promise|ExecutionResult|ExecutionResult[] $result
 * @param ResponseInterface $response
 * @param StreamInterface $writableBodyStream
 * @return Promise|ResponseInterface
 */
function toPsrResponse(
    $result,
    Psr\Http\Message\ResponseInterface $response,
    Psr\Http\Message\StreamInterface $writableBodyStream
)
```



<a name="graphqlserveroperationparams"></a>
# GraphQL\Server\OperationParams
表示 GraphQL 操作的已解析 HTTP 参数的结构。

**类属性:**
```php
/**
 * 查询的 ID (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
 * @var array
 */
public $variables;
```

**类方法:**
```php
/**
 * 从给定数组创建实例
 *
 * @api
 * @param array $params
 * @param bool $readonly
 * @return OperationParams
 */
static function create(array $params, $readonly = false)
```

```php
/**
 * @api
 * @param string $key
 * @return mixed
 */
function getOriginalInput($key)
```

```php
/**
 * 表示操作是在只读上下文中执行的
 * (例如：通过 HTTP GET 请求)
 *
 * @api
 * @return bool
 */
function isReadOnly()
```



<a name="graphqlutilsbuildschema"></a>
# GraphQL\Utils\BuildSchema
构建 `GraphQL\Type\Schema` 实例，脱离类型语言定义 (字符串或 AST 语法) 详情请参阅 [文档中的部分](https://laravel-china.org/docs/graphql-php/type-system-type-language)。

**类方法：**
```php
/**
 * This takes the ast of a schema document produced by the parse function in
 * GraphQL\Language\Parser.
 *
 * 如果没有提供 schema 定义，那么它将查询名为 Query 和 Mutation 类型。
 *
 * 给定的 AST 它构建了一个 GraphQL\Type\Schema。生成的 schema
 * 没有解析方法，因此执行将使用默认的解析程序。
 *
 * 接受选项作为第二个参数:
 *
 * - 注释描述：
 * 提供 true 以使用前面的注释作为描述。
 *
 *
 * @api
 * @param DocumentNode $ast
 * @param array $options
 * @return Schema
 * @throws Error
 */
static function buildAST(GraphQL\Language\AST\DocumentNode $ast, array $options = [])
```




```php
/**
 * 直接从源代码构建 GraphQL Schema 的辅助函数文档
 * 
 *
 * @api
 * @param DocumentNode|Source|string $source
 * @param array $options
 * @return Schema
 */
static function build($source, array $options = [])
```




# GraphQL\Utils\AST
使用 AST 处理多种实用程序

**类方法：**
```php
/**
 * 转换 AST 代表作为一个关联数组，去实例化 GraphQL\Language\AST\Node。
 *
 * 示例：
 *
 * ```php
 * AST::fromArray([
 *     'kind' => 'ListValue',
 *     'values' => [
 *         ['kind' => 'StringValue', 'value' => 'my str'],
 *         ['kind' => 'StringValue', 'value' => 'my other str']
 *     ],
 *     'loc' => ['start' => 21, 'end' => 25]
 * ]);
 * ```
 *
 * 将产生`ListValueNode` 的实例，其中 `values` 属性是懒惰的 `NodeList`
 * 返回 `StringValueNode` 的实例。
 *
 * 这是 AST::toArray($node) 的反向操作。
 *
 * @api
 * @param array $node
 * @return Node
 */
static function fromArray(array $node)
```

```php
/**
 * 反转 AST 节点为序列化数组。
 *
 * @api
 * @param Node $node
 * @return array
 */
static function toArray(GraphQL\Language\AST\Node $node)
```

```php
/**
 * 给定 PHP 值产生一个 GraphQL 值 AST。
 *
 * 可选的， a可以提供GraphQL类型，将用于在价值原语之间消除歧义。
 *
 * | 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            |
 *
 * @api
 * @param $value
 * @param InputType $type
 * @return ObjectValueNode|ListValueNode|BooleanValueNode|IntValueNode|FloatValueNode|EnumValueNode|StringValueNode|NullValueNode
 */
static function astFromValue($value, GraphQL\Type\Definition\InputType $type)
```




```php
/**
 * 给定 GraphQL 值 AST 产生 PHP 值。
 *
 * 必须提供 GraphQL 类型，该类型将用于解释不同的
 * GraphQl值文字。
 *
 * 返回`null`当该值无法根据提供的类型。
 *
 * | GraphQL Value        | PHP Value     |
 * | -------------------- | ------------- |
 * | Input Object         | Assoc Array   |
 * | List                 | Array         |
 * | Boolean              | Boolean       |
 * | String               | String        |
 * | Int / Float          | Int / Float   |
 * | Enum Value           | Mixed         |
 * | Null Value           | null          |
 *
 * @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)
```

```php
/**
 * 给定GraphQL值AST产生PHP值。
 *
 * 与 `valuefromast()` 不同，没有提供类型。由此产生的 JavaScript 值将反映提供的 GraphQL 值 AST。
 *
 * | GraphQL Value        | PHP Value     |
 * | -------------------- | ------------- |
 * | Input Object         | Assoc Array   |
 * | List                 | Array         |
 * | Boolean              | Boolean       |
 * | String               | String        |
 * | Int / Float          | Int / Float   |
 * | Enum                 | Mixed         |
 * | Null                 | null          |
 *
 * @api
 * @param Node $valueNode
 * @param array|null $variables
 * @return mixed
 * @throws \Exception
 */
static function valueFromASTUntyped($valueNode, array $variables = null)
```




```php
/**
 * 返回给定 AST Type 节点的类型定义
 *
 * @api
 * @param Schema $schema
 * @param NamedTypeNode|ListTypeNode|NonNullTypeNode $inputTypeNode
 * @return Type
 * @throws \Exception
 */
static function typeFromAST(GraphQL\Type\Schema $schema, $inputTypeNode)
```

```php
/**
 * 给定文档和操作名称，返回操作类型（“查询”，“变异” 或者“订阅”）
 * Returns operation type ("query", "mutation" or "subscription") given a document and operation name
 *
 * @api
 * @param DocumentNode $document
 * @param string $operationName
 * @return bool
 */
static function getOperation(GraphQL\Language\AST\DocumentNode $document, $operationName = null)
```



<a  name="graphql-utils-schema-printer"></a>
# GraphQL\Utils\SchemaPrinter
给定 Schema 的实例，以 GraphQL 类型语音打印它。

**Class Methods:** 
```php
/**
 * 接受选项作为第二个参数：
 *
 *    - 注释说明：
 *        为 true 时使用前面的注释作为描述。
 * @api
 * @param Schema $schema
 * @return string
 */
static function doPrint(GraphQL\Type\Schema $schema, array $options = [])
```

```php
/**
 * @api
 * @param Schema $schema
 * @return string
 */
static function printIntrosepctionSchema(GraphQL\Type\Schema $schema, array $options = [])
```
