GraphQL LogoGraphQL 中文网


graphql/execution 模块负责完成 GraphQL 请求的执行阶段。你可以从 graphql/execution 模块或根 graphql 模块导入。例如:

英:The graphql/execution module is responsible for the execution phase of fulfilling a GraphQL request. You can import either from the graphql/execution module, or from the root graphql module. For example:

import { execute } from "graphql" // ES6
var { execute } = require("graphql") // CommonJS






export function execute(
schema: GraphQLSchema,
documentAST: Document,
rootValue?: mixed,
contextValue?: mixed,
variableValues?: ?{[key: string]: mixed},
operationName?: ?string
): MaybePromise<ExecutionResult>
type MaybePromise<T> = Promise<T> | T;
type ExecutionResult = {
data: ?Object;
errors?: Array<GraphQLError>;

实现 GraphQL 规范的 "评估请求" 部分。

英:Implements the "Evaluating requests" section of the GraphQL specification.

返回一个最终会被解决并且永远不会被拒绝的 Promise。

英:Returns a Promise that will eventually be resolved and never rejected.

如果该函数的参数没有产生合法的执行上下文,则会立即抛出 GraphQLError 来解释无效的输入。

英:If the arguments to this function do not result in a legal execution context, a GraphQLError will be thrown immediately explaining the invalid input.

ExecutionResult 代表执行结果。data 是执行查询的结果,如果没有发生错误则 errors 为空,如果发生错误则为非空数组。

英:ExecutionResult represents the result of execution. data is the result of executing the query, errors is null if no errors occurred, and is a non-empty array if an error occurred.

继续阅读 →graphql/语言
GraphQL 中文网 - 粤ICP备13048890号