UNPKG

2.29 kBTypeScriptView Raw
1import Maybe from '../tsutils/Maybe';
2import { GraphQLError } from '../error/GraphQLError';
3import {
4 FieldNode,
5 DirectiveNode,
6 VariableDefinitionNode,
7} from '../language/ast';
8
9import { GraphQLDirective } from '../type/directives';
10import { GraphQLSchema } from '../type/schema';
11import {
12 GraphQLInputType,
13 GraphQLField,
14 GraphQLArgument,
15} from '../type/definition';
16
17type CoercedVariableValues =
18 | { errors: ReadonlyArray<GraphQLError>; coerced?: never }
19 | { errors?: never; coerced: { [key: string]: any } };
20
21/**
22 * Prepares an object map of variableValues of the correct type based on the
23 * provided variable definitions and arbitrary input. If the input cannot be
24 * parsed to match the variable definitions, a GraphQLError will be thrown.
25 *
26 * Note: The returned value is a plain Object with a prototype, since it is
27 * exposed to user code. Care should be taken to not pull values from the
28 * Object prototype.
29 */
30export function getVariableValues(
31 schema: GraphQLSchema,
32 varDefNodes: VariableDefinitionNode[],
33 inputs: { [key: string]: any },
34 options?: { maxErrors?: number },
35): CoercedVariableValues;
36
37/**
38 * Prepares an object map of argument values given a list of argument
39 * definitions and list of argument AST nodes.
40 *
41 * Note: The returned value is a plain Object with a prototype, since it is
42 * exposed to user code. Care should be taken to not pull values from the
43 * Object prototype.
44 */
45export function getArgumentValues(
46 def: GraphQLField<any, any> | GraphQLDirective,
47 node: FieldNode | DirectiveNode,
48 variableValues?: Maybe<{ [key: string]: any }>,
49): { [key: string]: any };
50
51/**
52 * Prepares an object map of argument values given a directive definition
53 * and a AST node which may contain directives. Optionally also accepts a map
54 * of variable values.
55 *
56 * If the directive does not exist on the node, returns undefined.
57 *
58 * Note: The returned value is a plain Object with a prototype, since it is
59 * exposed to user code. Care should be taken to not pull values from the
60 * Object prototype.
61 */
62export function getDirectiveValues(
63 directiveDef: GraphQLDirective,
64 node: {
65 readonly directives?: ReadonlyArray<DirectiveNode>;
66 },
67 variableValues?: Maybe<{ [key: string]: any }>,
68): undefined | { [key: string]: any };