1 | import Maybe from './tsutils/Maybe';
|
2 | import { Source } from './language/source';
|
3 | import { GraphQLSchema } from './type/schema';
|
4 | import { GraphQLFieldResolver, GraphQLTypeResolver } from './type/definition';
|
5 | import {
|
6 | ExecutionResult,
|
7 | ExecutionResultDataDefault,
|
8 | } from './execution/execute';
|
9 |
|
10 | /**
|
11 | * This is the primary entry point function for fulfilling GraphQL operations
|
12 | * by parsing, validating, and executing a GraphQL document along side a
|
13 | * GraphQL schema.
|
14 | *
|
15 | * More sophisticated GraphQL servers, such as those which persist queries,
|
16 | * may wish to separate the validation and execution phases to a static time
|
17 | * tooling step, and a server runtime step.
|
18 | *
|
19 | * Accepts either an object with named arguments, or individual arguments:
|
20 | *
|
21 | * schema:
|
22 | * The GraphQL type system to use when validating and executing a query.
|
23 | * source:
|
24 | * A GraphQL language formatted string representing the requested operation.
|
25 | * rootValue:
|
26 | * The value provided as the first argument to resolver functions on the top
|
27 | * level type (e.g. the query object type).
|
28 | * contextValue:
|
29 | * The context value is provided as an argument to resolver functions after
|
30 | * field arguments. It is used to pass shared information useful at any point
|
31 | * during executing this query, for example the currently logged in user and
|
32 | * connections to databases or other services.
|
33 | * variableValues:
|
34 | * A mapping of variable name to runtime value to use for all variables
|
35 | * defined in the requestString.
|
36 | * operationName:
|
37 | * The name of the operation to use if requestString contains multiple
|
38 | * possible operations. Can be omitted if requestString contains only
|
39 | * one operation.
|
40 | * fieldResolver:
|
41 | * A resolver function to use when one is not provided by the schema.
|
42 | * If not provided, the default field resolver is used (which looks for a
|
43 | * value or method on the source value with the field's name).
|
44 | */
|
45 | export interface GraphQLArgs {
|
46 | schema: GraphQLSchema;
|
47 | source: string | Source;
|
48 | rootValue?: any;
|
49 | contextValue?: any;
|
50 | variableValues?: Maybe<{ [key: string]: any }>;
|
51 | operationName?: Maybe<string>;
|
52 | fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>;
|
53 | typeResolver?: Maybe<GraphQLTypeResolver<any, any>>;
|
54 | }
|
55 |
|
56 | export function graphql<TData = ExecutionResultDataDefault>(
|
57 | args: GraphQLArgs,
|
58 | ): Promise<ExecutionResult<TData>>;
|
59 | export function graphql<TData = ExecutionResultDataDefault>(
|
60 | schema: GraphQLSchema,
|
61 | source: Source | string,
|
62 | rootValue?: any,
|
63 | contextValue?: any,
|
64 | variableValues?: Maybe<{ [key: string]: any }>,
|
65 | operationName?: Maybe<string>,
|
66 | fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>,
|
67 | typeResolver?: Maybe<GraphQLTypeResolver<any, any>>,
|
68 | ): Promise<ExecutionResult<TData>>;
|
69 |
|
70 | /**
|
71 | * The graphqlSync function also fulfills GraphQL operations by parsing,
|
72 | * validating, and executing a GraphQL document along side a GraphQL schema.
|
73 | * However, it guarantees to complete synchronously (or throw an error) assuming
|
74 | * that all field resolvers are also synchronous.
|
75 | */
|
76 | export function graphqlSync<TData = ExecutionResultDataDefault>(
|
77 | args: GraphQLArgs,
|
78 | ): ExecutionResult<TData>;
|
79 | export function graphqlSync<TData = ExecutionResultDataDefault>(
|
80 | schema: GraphQLSchema,
|
81 | source: Source | string,
|
82 | rootValue?: any,
|
83 | contextValue?: any,
|
84 | variableValues?: Maybe<{ [key: string]: any }>,
|
85 | operationName?: Maybe<string>,
|
86 | fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>,
|
87 | typeResolver?: Maybe<GraphQLTypeResolver<any, any>>,
|
88 | ): ExecutionResult<TData>;
|