UNPKG

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