9
9
10
10
import { validateSchema } from './type/validate' ;
11
11
import { parse } from './language/parser' ;
12
- import { validate } from './validation/validate ' ;
12
+ import { validate , specifiedRules } from './validation' ;
13
13
import { execute } from './execution/execute' ;
14
14
import type { ObjMap } from './jsutils/ObjMap' ;
15
- import type { Source } from './language/source ' ;
15
+ import type { ParseOptions , Source } from './language' ;
16
16
import type { GraphQLFieldResolver } from './type/definition' ;
17
17
import type { GraphQLSchema } from './type/schema' ;
18
18
import type { ExecutionResult } from './execution/execute' ;
19
+ import type { ValidationOptions } from './validation' ;
19
20
import type { MaybePromise } from './jsutils/MaybePromise' ;
20
21
21
22
/**
@@ -47,6 +48,9 @@ import type { MaybePromise } from './jsutils/MaybePromise';
47
48
* A resolver function to use when one is not provided by the schema.
48
49
* If not provided, the default field resolver is used (which looks for a
49
50
* value or method on the source value with the field's name).
51
+ * options:
52
+ * An additional set of flags which enable legacy, compataibility, or
53
+ * experimental behavior.
50
54
*/
51
55
export type GraphQLArgs = { |
52
56
schema : GraphQLSchema ,
@@ -56,6 +60,7 @@ export type GraphQLArgs = {|
56
60
variableValues ?: ?ObjMap < mixed > ,
57
61
operationName ?: ?string ,
58
62
fieldResolver ?: ?GraphQLFieldResolver < any , any > ,
63
+ options ?: ParseOptions & ValidationOptions ,
59
64
| } ;
60
65
declare function graphql ( GraphQLArgs , ..._ : [ ] ) : Promise < ExecutionResult > ;
61
66
/* eslint-disable no-redeclare */
@@ -67,6 +72,7 @@ declare function graphql(
67
72
variableValues ?: ?ObjMap < mixed > ,
68
73
operationName ?: ?string ,
69
74
fieldResolver ?: ?GraphQLFieldResolver < any , any > ,
75
+ options ?: ParseOptions & ValidationOptions ,
70
76
) : Promise < ExecutionResult > ;
71
77
export function graphql (
72
78
argsOrSchema ,
@@ -76,6 +82,7 @@ export function graphql(
76
82
variableValues ,
77
83
operationName ,
78
84
fieldResolver ,
85
+ options ,
79
86
) {
80
87
/* eslint-enable no-redeclare */
81
88
// Always return a Promise for a consistent API.
@@ -91,6 +98,7 @@ export function graphql(
91
98
argsOrSchema . variableValues ,
92
99
argsOrSchema . operationName ,
93
100
argsOrSchema . fieldResolver ,
101
+ argsOrSchema . options ,
94
102
)
95
103
: graphqlImpl (
96
104
argsOrSchema ,
@@ -100,6 +108,7 @@ export function graphql(
100
108
variableValues ,
101
109
operationName ,
102
110
fieldResolver ,
111
+ options ,
103
112
) ,
104
113
) ,
105
114
) ;
@@ -121,6 +130,7 @@ declare function graphqlSync(
121
130
variableValues ?: ?ObjMap < mixed > ,
122
131
operationName ?: ?string ,
123
132
fieldResolver ?: ?GraphQLFieldResolver < any , any > ,
133
+ options ?: ParseOptions & ValidationOptions ,
124
134
) : ExecutionResult ;
125
135
export function graphqlSync (
126
136
argsOrSchema ,
@@ -130,6 +140,7 @@ export function graphqlSync(
130
140
variableValues ,
131
141
operationName ,
132
142
fieldResolver ,
143
+ options ,
133
144
) {
134
145
// Extract arguments from object args if provided.
135
146
const result =
@@ -142,6 +153,7 @@ export function graphqlSync(
142
153
argsOrSchema . variableValues ,
143
154
argsOrSchema . operationName ,
144
155
argsOrSchema . fieldResolver ,
156
+ argsOrSchema . options ,
145
157
)
146
158
: graphqlImpl (
147
159
argsOrSchema ,
@@ -151,6 +163,7 @@ export function graphqlSync(
151
163
variableValues ,
152
164
operationName ,
153
165
fieldResolver ,
166
+ options ,
154
167
) ;
155
168
156
169
// Assert that the execution was synchronous.
@@ -169,6 +182,7 @@ function graphqlImpl(
169
182
variableValues ,
170
183
operationName ,
171
184
fieldResolver ,
185
+ options ,
172
186
) : MaybePromise < ExecutionResult > {
173
187
// Validate Schema
174
188
const schemaValidationErrors = validateSchema ( schema ) ;
@@ -179,13 +193,13 @@ function graphqlImpl(
179
193
// Parse
180
194
let document ;
181
195
try {
182
- document = parse ( source ) ;
196
+ document = parse ( source , options ) ;
183
197
} catch ( syntaxError ) {
184
198
return { errors : [ syntaxError ] } ;
185
199
}
186
200
187
201
// Validate
188
- const validationErrors = validate ( schema , document ) ;
202
+ const validationErrors = validate ( schema , document , specifiedRules , options ) ;
189
203
if ( validationErrors . length > 0 ) {
190
204
return { errors : validationErrors } ;
191
205
}
0 commit comments