graphql/execution/values

Functions

getVariableValues()

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.

Signature:

getVariableValues(schema: GraphQLSchema, varDefNodes: readonly VariableDefinitionNode[], inputs: object, options?: GetVariableValuesOptions): { errors: ReadonlyArray<GraphQLError>; coerced?: never } | { coerced: object; errors?: never }

Arguments

NameTypeDescription
schemaGraphQLSchemaThe GraphQL schema to use.
varDefNodesreadonly VariableDefinitionNode[]The variable definition AST nodes to coerce.
inputsobjectThe runtime variable values keyed by variable name.
options?GetVariableValuesOptionsOptional configuration for this operation.

Returns

TypeDescription
{ errors: ReadonlyArray<GraphQLError>; coerced?: never } | { coerced: object; errors?: never }The resolved variable values.

Example

import { getVariableValues } from 'graphql/execution';
 
const result = getVariableValues(schema, varDefNodes, inputs);
 
// result contains the getVariableValues return value

getArgumentValues()

Prepares an object map of argument values given a list of argument definitions and list of argument AST nodes.

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.

Signature:

getArgumentValues(def: GraphQLField<unknown, unknown> | GraphQLDirective, node: FieldNode | DirectiveNode, variableValues?: null | undefined | object): object

Arguments

NameTypeDescription
defGraphQLField<unknown, unknown> | GraphQLDirectiveThe field or directive definition whose arguments should be coerced.
nodeFieldNode | DirectiveNodeThe AST node to inspect.
variableValues?null | undefined | objectThe runtime variable values keyed by variable name.

Returns

TypeDescription
objectThe resolved argument values.

Example

import { getArgumentValues } from 'graphql/execution';
 
const result = getArgumentValues(def, node);
 
// result contains the getArgumentValues return value

getDirectiveValues()

Prepares an object map of argument values given a directive definition and a AST node which may contain directives. Optionally also accepts a map of variable values.

If the directive does not exist on the node, returns undefined.

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.

Signature:

getDirectiveValues(directiveDef: GraphQLDirective, node: DirectiveValuesNode, variableValues?: null | undefined | object): object | undefined

Arguments

NameTypeDescription
directiveDefGraphQLDirectiveThe directive definition whose arguments should be coerced.
nodeDirectiveValuesNodeThe AST node to inspect.
variableValues?null | undefined | objectThe runtime variable values keyed by variable name.

Returns

TypeDescription
object | undefinedThe resolved directive values.

Example

import { getDirectiveValues } from 'graphql/execution';
 
const result = getDirectiveValues(directiveDef, node);
 
// result contains the getDirectiveValues return value

Types

GetVariableValuesOptions

Interface. Options used when coercing variable values before execution.

Members

NameTypeDescription
maxErrors?numberMaximum number of variable coercion errors before coercion stops.

DirectiveValuesNode

Interface. AST node shape accepted by getDirectiveValues.

Members

NameTypeDescription
directives?readonly DirectiveNode[]Directives attached to the AST node.