v17 APIgraphql

graphql

The root graphql entry point exports the graphql() request function and re-exports the public GraphQL.js API from the original submodules. It is the most convenient import path for applications, while the submodule pages in this section document the same exports by area. You can import from the root package or from individual modules such as graphql/execution, graphql/language, and graphql/type; the root package gathers those public exports in one place.

import { graphql, GraphQLSchema, parse, execute } from 'graphql';

Contents

Request Entry Points

ExportKindDescription
graphql() Changed in v17FunctionParses, validates, and executes one operation and always returns a promise for a single ExecutionResult. v17 accepts parser, validation, execution, and harness options through GraphQLArgs.
graphqlSync() Changed in v17FunctionRuns the same pipeline synchronously and throws if a phase or resolver becomes asynchronous.
GraphQLArgs Changed in v17TypeObject accepted by graphql() and graphqlSync(). In v17 it combines parse, validation, execution, and harness options.
function graphql(args: GraphQLArgs): Promise<ExecutionResult>;
function graphqlSync(args: GraphQLArgs): ExecutionResult;
const result = await graphql({
  schema,
  source: 'query Viewer($id: ID!) { viewer(id: $id) { name } }',
  variableValues: { id: '1' },
  contextValue: { currentUser },
});

Version Exports

ExportKindDescription
versionConstantThe GraphQL.js package version string.
versionInfoConstantParsed version components: major, minor, patch, and preReleaseTag.

Development Mode Exports

Development mode is documented on the root graphql entry point in v17. It is not a separate API section.

ExportKindDescription
enableDevMode() New in v17FunctionEnables development checks for this GraphQL.js module instance.
isDevModeEnabled() New in v17FunctionReturns whether development mode has been enabled.
import { enableDevMode, isDevModeEnabled } from 'graphql';
 
if (process.env.NODE_ENV === 'development') {
  enableDevMode();
}
 
console.log(isDevModeEnabled());

In v16 and earlier, GraphQL.js development checks were controlled by NODE_ENV. In v17, NODE_ENV is ignored by GraphQL.js itself. Use the development package condition or call enableDevMode() explicitly.

Root Exports by Area

ExportArea
enableDevMode, isDevModeEnabled New in v17Development mode.
defaultHarness, GraphQLHarness, GraphQLParseFn, GraphQLValidateFn, GraphQLExecuteFn, GraphQLSubscribeFn New in v17graphql() phase customization.
ExecutionArgs, ExecutionResult, FormattedExecutionResult, ValidatedExecutionArgs, ValidatedSubscriptionArgs, RootSelectionSetExecutorExecution and subscription types.
execute, executeSync, subscribe, createSourceEventStream, defaultFieldResolver, defaultTypeResolver, responsePathAsArrayCore execution and subscription helpers.
validateExecutionArgs, validateSubscriptionArgs, executeRootSelectionSet, executeSubscriptionEvent, experimentalExecuteRootSelectionSet, mapSourceToResponseEvent, experimentalExecuteIncrementally New in v17Pipeline split and incremental delivery helpers.
AbortedGraphQLExecutionError New in v17Abort error class.
ExecutionHooks, AsyncWorkFinishedInfo New in v17Execution hook types.
ExperimentalIncrementalExecutionResults, InitialIncrementalExecutionResult, SubsequentIncrementalExecutionResult, IncrementalDeferResult, IncrementalStreamResult, IncrementalResult and their Formatted* counterparts New in v17Incremental delivery types.
getArgumentValues, getVariableValues, getDirectiveValuesArgument and variable coercion helpers.
GraphQLError, syntaxError, locatedErrorError creation and formatting helpers.
validate, ValidationContext, ValidationRule, specifiedRules, recommendedRules, and the individual validation rulesValidation entry points and rule sets.
Source, Location, Token, parse, parseValue, parseConstValue, parseType, parseSchemaCoordinate, print, visit, visitInParallel, getVisitFn, getEnterLeaveForKind, BREAK, Kind, DirectiveLocation, OperationTypeNodeLanguage and AST helpers.
GraphQLField, GraphQLArgument, GraphQLInputField, GraphQLEnumValue, isField, assertField, isArgument, assertArgument, isInputField, assertInputField, isEnumValue, assertEnumValue New in v17Public field-like schema element types and predicates.
introspectionFromSchema, getIntrospectionQuery, buildClientSchema, buildASTSchema, buildSchema, extendSchema, lexicographicSortSchema, printSchema, printType, printIntrospectionSchema, typeFromAST, valueFromAST, valueFromASTUntyped, astFromValue, TypeInfo, visitWithTypeInfo, coerceInputValue, concatAST, separateOperations, stripIgnoredCharacters, isEqualType, isTypeSubTypeOf, doTypesOverlap, assertValidName, isValidNameError, BreakingChangeType, DangerousChangeType, findBreakingChanges, findDangerousChanges, resolveSchemaCoordinate, resolveASTSchemaCoordinateUtility helpers.
GraphQLDeferDirective, GraphQLStreamDirective New in v17Experimental incremental delivery directives.
printDirective, findSchemaChanges, SafeChangeType, SafeChange New in v17Schema printing and schema evolution reporting.
DeferStreamDirectiveLabelRule, DeferStreamDirectiveOnRootFieldRule, DeferStreamDirectiveOnValidOperationsRule, KnownOperationTypesRule, StreamDirectiveOnListFieldRule New in v17Additional validation rules.
valueFromAST, astFromValue, findBreakingChanges, findDangerousChanges Deprecated in v17Legacy utilities kept for compatibility.

Export Map

AreaAPI reference
Request pipelinegraphql
Errorsgraphql/error
Execution and subscriptionsgraphql/execution
Language, AST, parser, printer, visitorgraphql/language
Schema and type systemgraphql/type
Utilitiesgraphql/utilities
Validationgraphql/validation

GraphQLArgs

interface GraphQLArgs
  extends ParseOptions,
    ValidationOptions,
    Omit<ExecutionArgs, 'document'> {
  source: string | Source;
  rules?: ReadonlyArray<ValidationRule>;
  harness?: GraphQLHarness;
}

GraphQLArgs is deliberately broad in v17:

  • Parser options such as noLocation and experimental syntax flags are accepted directly.
  • Validation options such as maxErrors and hideSuggestions are accepted directly.
  • Execution options such as abortSignal, fieldResolver, typeResolver, and hooks are accepted directly.
  • harness can replace the built-in parse, validation, execution, or subscription phases.
import { graphql } from 'graphql';
 
const controller = new AbortController();
 
const result = await graphql({
  schema,
  source,
  variableValues,
  operationName: 'Viewer',
  hideSuggestions: true,
  abortSignal: controller.signal,
});

For incremental delivery, parse and validate separately, then call experimentalExecuteIncrementally(). The convenience graphql() function is a single-result API.