@@ -16,7 +16,6 @@ import type { GraphQLFieldResolver } from './type/definition';
16
16
import type { GraphQLSchema } from './type/schema' ;
17
17
import type { ExecutionResult } from './execution/execute' ;
18
18
19
-
20
19
/**
21
20
* This is the primary entry point function for fulfilling GraphQL operations
22
21
* by parsing, validating, and executing a GraphQL document along side a
@@ -26,6 +25,8 @@ import type { ExecutionResult } from './execution/execute';
26
25
* may wish to separate the validation and execution phases to a static time
27
26
* tooling step, and a server runtime step.
28
27
*
28
+ * Accepts either an object with named arguments, or individual arguments:
29
+ *
29
30
* schema:
30
31
* The GraphQL type system to use when validating and executing a query.
31
32
* source:
@@ -45,25 +46,58 @@ import type { ExecutionResult } from './execution/execute';
45
46
* If not provided, the default field resolver is used (which looks for a
46
47
* value or method on the source value with the field's name).
47
48
*/
48
- export function graphql (
49
+ declare function graphql ( { |
49
50
schema : GraphQLSchema ,
50
51
source : string | Source ,
51
52
rootValue ?: mixed ,
52
53
contextValue ?: mixed ,
53
54
variableValues ?: ?{ [ key : string ] : mixed } ,
54
55
operationName ?: ?string ,
55
56
fieldResolver ?: ?GraphQLFieldResolver < any , any>
56
- ) : Promise < ExecutionResult > {
57
+ | } , ..._ : [ ] ) : Promise < ExecutionResult > ;
58
+ /* eslint-disable no-redeclare */
59
+ declare function graphql(
60
+ schema: GraphQLSchema,
61
+ source: Source | string,
62
+ rootValue?: mixed,
63
+ contextValue?: mixed,
64
+ variableValues?: ?{ [ key : string ] : mixed } ,
65
+ operationName?: ?string,
66
+ fieldResolver?: ?GraphQLFieldResolver< any , any >
67
+ ): Promise< ExecutionResult > ;
68
+ export function graphql(
69
+ argsOrSchema,
70
+ source,
71
+ rootValue,
72
+ contextValue,
73
+ variableValues,
74
+ operationName,
75
+ fieldResolver
76
+ ) {
77
+ // Extract arguments from object args if provided.
78
+ const args = arguments . length === 1 ? argsOrSchema : undefined ;
79
+ const schema = args ? args . schema : argsOrSchema ;
80
+ if ( args ) {
81
+ /* eslint-disable no-param-reassign */
82
+ source = args . source ;
83
+ rootValue = args . rootValue ;
84
+ contextValue = args . contextValue ;
85
+ variableValues = args . variableValues ;
86
+ operationName = args . operationName ;
87
+ fieldResolver = args . fieldResolver ;
88
+ /* eslint-enable no-param-reassign, no-redeclare */
89
+ }
90
+
57
91
return new Promise ( resolve => {
58
- const documentAST = parse ( source ) ;
59
- const validationErrors = validate ( schema , documentAST ) ;
92
+ const document = parse ( source ) ;
93
+ const validationErrors = validate ( schema , document ) ;
60
94
if ( validationErrors . length > 0 ) {
61
95
resolve ( { errors : validationErrors } ) ;
62
96
} else {
63
97
resolve (
64
98
execute (
65
99
schema ,
66
- documentAST ,
100
+ document ,
67
101
rootValue ,
68
102
contextValue ,
69
103
variableValues ,
0 commit comments