UNPKG

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