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
| Name | Type | Description |
|---|---|---|
| schema | GraphQLSchema | The GraphQL schema to use. |
| varDefNodes | readonly VariableDefinitionNode[] | The variable definition AST nodes to coerce. |
| inputs | object | The runtime variable values keyed by variable name. |
| options? | GetVariableValuesOptions | Optional configuration for this operation. |
Returns
| Type | Description |
|---|---|
{ 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 valuegetArgumentValues()
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
| Name | Type | Description |
|---|---|---|
| def | GraphQLField<unknown, unknown> | GraphQLDirective | The field or directive definition whose arguments should be coerced. |
| node | FieldNode | DirectiveNode | The AST node to inspect. |
| variableValues? | null | undefined | object | The runtime variable values keyed by variable name. |
Returns
| Type | Description |
|---|---|
object | The resolved argument values. |
Example
import { getArgumentValues } from 'graphql/execution';
const result = getArgumentValues(def, node);
// result contains the getArgumentValues return valuegetDirectiveValues()
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
| Name | Type | Description |
|---|---|---|
| directiveDef | GraphQLDirective | The directive definition whose arguments should be coerced. |
| node | DirectiveValuesNode | The AST node to inspect. |
| variableValues? | null | undefined | object | The runtime variable values keyed by variable name. |
Returns
| Type | Description |
|---|---|
object | undefined | The resolved directive values. |
Example
import { getDirectiveValues } from 'graphql/execution';
const result = getDirectiveValues(directiveDef, node);
// result contains the getDirectiveValues return valueTypes
GetVariableValuesOptions
Interface. Options used when coercing variable values before execution.
Members
| Name | Type | Description |
|---|---|---|
| maxErrors? | number | Maximum number of variable coercion errors before coercion stops. |
DirectiveValuesNode
Interface. AST node shape accepted by getDirectiveValues.
Members
| Name | Type | Description |
|---|---|---|
| directives? | readonly DirectiveNode[] | Directives attached to the AST node. |