📣 GraphQLConf 2025 • Sept 08-10 • Amsterdam • Early bird tickets available & sponsorship opportunities open • Learn more
GraphQL.JS Tutorial
graphql/execution

graphql/execution

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

Overview

Execution

execute

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?: GraphQLError[];
}

Implements the “Evaluating requests” section of the GraphQL specification.

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

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 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.