Documentation
API Reference
Packages
executor

@graphql-tools/executor

Interfaces

Type Aliases

Functions

Type Aliases

FormattedIncrementalResult

Ƭ FormattedIncrementalResult<TData, TExtensions>: FormattedIncrementalDeferResult<TData, TExtensions> | FormattedIncrementalStreamResult<TData, TExtensions>

Type parameters

NameType
TDataRecord<string, unknown>
TExtensionsRecord<string, unknown>

Defined in

packages/executor/src/execution/execute.ts:227


IncrementalResult

Ƭ IncrementalResult<TData, TExtensions>: IncrementalDeferResult<TData, TExtensions> | IncrementalStreamResult<TData, TExtensions>

Type parameters

NameType
TDataRecord<string, unknown>
TExtensionsRecord<string, unknown>

Defined in

packages/executor/src/execution/execute.ts:222

Functions

assertValidExecutionArguments

assertValidExecutionArguments<TVariables>(schema, document, rawVariableValues): void

Essential assertions before executing to provide developer feedback for improper use of the GraphQL library.

Type parameters

Name
TVariables

Parameters

NameType
schemaGraphQLSchema
documentTypedDocumentNode<any, TVariables>
rawVariableValuesMaybe<TVariables>

Returns

void

Defined in

packages/executor/src/execution/execute.ts:368


buildExecutionContext

buildExecutionContext<TData, TVariables, TContext>(args): ReadonlyArray<GraphQLError> | ExecutionContext

Constructs a ExecutionContext object from the arguments passed to execute, which we will pass throughout the other execution methods.

Throws a GraphQLError if a valid execution context cannot be created.

TODO: consider no longer exporting this function

Type parameters

NameType
TDataany
TVariablesany
TContextany

Parameters

NameType
argsExecutionArgs<TData, TVariables, TContext>

Returns

ReadonlyArray<GraphQLError> | ExecutionContext

Defined in

packages/executor/src/execution/execute.ts:406


buildResolveInfo

buildResolveInfo(exeContext, fieldDef, fieldNodes, parentType, path): GraphQLResolveInfo

TODO: consider no longer exporting this function

Parameters

NameType
exeContextExecutionContext<any, any>
fieldDefGraphQLField<unknown, unknown, any>
fieldNodesFieldNode[]
parentTypeGraphQLObjectType<any, any>
pathPath

Returns

GraphQLResolveInfo

Defined in

packages/executor/src/execution/execute.ts:714


defaultFieldResolver

defaultFieldResolver(source, args, context, info): unknown

If a resolve function is not given, then a default resolve behavior is used which takes the property of the source object of the same name as the field and returns it as the result, or if it’s a function, returns the result of calling that function while passing along args and context value.

Parameters

NameType
sourceunknown
argsany
contextunknown
infoGraphQLResolveInfo

Returns

unknown

Defined in

packages/executor/src/execution/execute.ts:1434


defaultTypeResolver

defaultTypeResolver(value, context, info, abstractType): PromiseOrValue<undefined | string>

If a resolveType function is not given, then a default resolve behavior is used which attempts two strategies:

First, See if the provided value has a __typename field defined, if so, use that value as name of the resolved type.

Otherwise, test each possible type for the abstract type by calling isTypeOf for the object being coerced, returning the first type that matches.

Parameters

NameType
valueunknown
contextunknown
infoGraphQLResolveInfo
abstractTypeGraphQLAbstractType

Returns

PromiseOrValue<undefined | string>

Defined in

packages/executor/src/execution/execute.ts:1388


execute

execute<TData, TVariables, TContext>(args): MaybePromise<SingularExecutionResult<TData> | IncrementalExecutionResults<TData>>

Implements the “Executing requests” section of the GraphQL specification, including @defer and @stream as proposed in https://github.com/graphql/graphql-spec/pull/742

This function returns a Promise of an IncrementalExecutionResults object. This object either consists of a single ExecutionResult, or an object containing an initialResult and a stream of subsequentResults.

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

Type parameters

NameType
TDataany
TVariablesany
TContextany

Parameters

NameType
argsExecutionArgs<TData, TVariables, TContext>

Returns

MaybePromise<SingularExecutionResult<TData> | IncrementalExecutionResults<TData>>

Defined in

packages/executor/src/execution/execute.ts:259


executeSync

executeSync(args): SingularExecutionResult

Also implements the “Executing requests” section of the GraphQL specification. However, it guarantees to complete synchronously (or throw an error) assuming that all field resolvers are also synchronous.

Parameters

NameType
argsExecutionArgs<any, any, any>

Returns

SingularExecutionResult

Defined in

packages/executor/src/execution/execute.ts:340


flattenIncrementalResults

flattenIncrementalResults<TData>(incrementalResults): AsyncGenerator<SubsequentIncrementalExecutionResult<TData, Record<string, unknown>>, void, void>

Type parameters

Name
TData

Parameters

NameType
incrementalResultsIncrementalExecutionResults<TData, Record<string, unknown>>

Returns

AsyncGenerator<SubsequentIncrementalExecutionResult<TData, Record<string, unknown>>, void, void>

Defined in

packages/executor/src/execution/execute.ts:1528


getFieldDef

getFieldDef(schema, parentType, fieldNode): Maybe<GraphQLField<unknown, unknown>>

This method looks up the field on the given type definition. It has special casing for the three introspection fields, __schema, __type and __typename. __typename is special because it can always be queried as a field, even in situations where no other fields are allowed, like on a Union. __schema and __type could get automatically added to the query type, but that would require mutating type definitions, which would cause issues.

Parameters

NameType
schemaGraphQLSchema
parentTypeGraphQLObjectType<any, any>
fieldNodeFieldNode

Returns

Maybe<GraphQLField<unknown, unknown>>

Defined in

packages/executor/src/execution/execute.ts:2221


getFragmentsFromDocument

getFragmentsFromDocument(document): Record<string, FragmentDefinitionNode>

Parameters

NameType
documentDocumentNode

Returns

Record<string, FragmentDefinitionNode>

Defined in

packages/executor/src/execution/execute.ts:385


getVariableValues

getVariableValues(schema, varDefNodes, inputs, options?): CoercedVariableValues

Prepares an object map of variableValues of the correct type based on the provided variable definitions and arbitrary input. If the input cannot be parsed to match the variable definitions, a GraphQLError will be thrown.

Note: The returned value is a plain Object with a prototype, since it is exposed to user code. Care should be taken to not pull values from the Object prototype.

Parameters

NameType
schemaGraphQLSchema
varDefNodesreadonly VariableDefinitionNode[]
inputsObject
options?Object
options.maxErrors?number

Returns

CoercedVariableValues

Defined in

packages/executor/src/execution/values.ts:28


isIncrementalResult

isIncrementalResult<TData>(result): result is IncrementalExecutionResults<TData, Record<string, unknown>>

Type parameters

Name
TData

Parameters

NameType
resultSingularExecutionResult<TData, any> | IncrementalExecutionResults<TData, Record<string, unknown>>

Returns

result is IncrementalExecutionResults<TData, Record<string, unknown>>

Defined in

packages/executor/src/execution/execute.ts:2238


normalizedExecutor

normalizedExecutor<TData, TVariables, TContext>(args): MaybePromise<MaybeAsyncIterable<ExecutionResult<TData>>>

Type parameters

NameType
TDataany
TVariablesany
TContextany

Parameters

NameType
argsExecutionArgs<TData, TVariables, TContext>

Returns

MaybePromise<MaybeAsyncIterable<ExecutionResult<TData>>>

Defined in

packages/executor/src/execution/normalizedExecutor.ts:6


subscribe

subscribe<TData, TVariables, TContext>(args): MaybePromise<AsyncGenerator<SingularExecutionResult<TData> | InitialIncrementalExecutionResult<TData> | SubsequentIncrementalExecutionResult<TData>, void, void> | SingularExecutionResult<TData>>

Implements the “Subscribe” algorithm described in the GraphQL specification, including @defer and @stream as proposed in https://github.com/graphql/graphql-spec/pull/742

Returns a Promise which resolves to either an AsyncIterator (if successful) or an ExecutionResult (error). The promise will be rejected if the schema or other arguments to this function are invalid, or if the resolved event stream is not an async iterable.

If the client-provided arguments to this function do not result in a compliant subscription, a GraphQL Response (ExecutionResult) with descriptive errors and no data will be returned.

If the source stream could not be created due to faulty subscription resolver logic or underlying systems, the promise will resolve to a single ExecutionResult containing errors and no data.

If the operation succeeded, the promise resolves to an AsyncIterator, which yields a stream of result representing the response stream.

Each result may be an ExecutionResult with no hasNext (if executing the event did not use @defer or @stream), or an InitialIncrementalExecutionResult or SubsequentIncrementalExecutionResult (if executing the event used @defer or @stream). In the case of incremental execution results, each event produces a single InitialIncrementalExecutionResult followed by one or more SubsequentIncrementalExecutionResults; all but the last have hasNext: true, and the last has hasNext: false. There is no interleaving between results generated from the same original event.

Accepts an object with named arguments.

Type parameters

NameType
TDataany
TVariablesany
TContextany

Parameters

NameType
argsExecutionArgs<TData, TVariables, TContext>

Returns

MaybePromise<AsyncGenerator<SingularExecutionResult<TData> | InitialIncrementalExecutionResult<TData> | SubsequentIncrementalExecutionResult<TData>, void, void> | SingularExecutionResult<TData>>

Defined in

packages/executor/src/execution/execute.ts:1483