@@ -78,6 +78,7 @@ export function collectFields(
78
78
runtimeType : GraphQLObjectType ,
79
79
selectionSet : SelectionSetNode ,
80
80
hideSuggestions : boolean ,
81
+ forbidSkipInclude = false ,
81
82
) : {
82
83
groupedFieldSet : GroupedFieldSet ;
83
84
newDeferUsages : ReadonlyArray < DeferUsage > ;
@@ -95,24 +96,22 @@ export function collectFields(
95
96
forbiddenDirectiveInstances : [ ] ,
96
97
} ;
97
98
98
- collectFieldsImpl ( context , selectionSet , groupedFieldSet , newDeferUsages ) ;
99
+ collectFieldsImpl (
100
+ context ,
101
+ selectionSet ,
102
+ groupedFieldSet ,
103
+ newDeferUsages ,
104
+ undefined ,
105
+ undefined ,
106
+ forbidSkipInclude ,
107
+ ) ;
99
108
return {
100
109
groupedFieldSet,
101
110
newDeferUsages,
102
111
forbiddenDirectiveInstances : context . forbiddenDirectiveInstances ,
103
112
} ;
104
113
}
105
114
106
- /**
107
- * This variable is the empty variables used during the validation phase (where
108
- * no variables exist) for field collection; if a `@skip` or `@include`
109
- * directive is ever seen when `variableValues` is set to this, it should
110
- * throw.
111
- */
112
- export const VALIDATION_PHASE_EMPTY_VARIABLES : VariableValues = Object . freeze (
113
- Object . create ( null ) ,
114
- ) ;
115
-
116
115
/**
117
116
* Given an array of field nodes, collects all of the subfields of the passed
118
117
* in fields, and returns them at the end.
@@ -134,6 +133,7 @@ export function collectSubfields(
134
133
) : {
135
134
groupedFieldSet : GroupedFieldSet ;
136
135
newDeferUsages : ReadonlyArray < DeferUsage > ;
136
+ forbiddenDirectiveInstances : ReadonlyArray < DirectiveNode > ;
137
137
} {
138
138
const context : CollectFieldsContext = {
139
139
schema,
@@ -177,6 +177,7 @@ function collectFieldsImpl(
177
177
newDeferUsages : Array < DeferUsage > ,
178
178
deferUsage ?: DeferUsage ,
179
179
fragmentVariableValues ?: VariableValues ,
180
+ forbidSkipInclude = false ,
180
181
) : void {
181
182
const {
182
183
schema,
@@ -197,6 +198,7 @@ function collectFieldsImpl(
197
198
variableValues ,
198
199
fragmentVariableValues ,
199
200
hideSuggestions ,
201
+ forbidSkipInclude ,
200
202
)
201
203
) {
202
204
continue ;
@@ -216,6 +218,7 @@ function collectFieldsImpl(
216
218
variableValues ,
217
219
fragmentVariableValues ,
218
220
hideSuggestions ,
221
+ forbidSkipInclude ,
219
222
) ||
220
223
! doesFragmentConditionMatch ( schema , selection , runtimeType )
221
224
) {
@@ -263,6 +266,7 @@ function collectFieldsImpl(
263
266
variableValues ,
264
267
fragmentVariableValues ,
265
268
hideSuggestions ,
269
+ forbidSkipInclude ,
266
270
)
267
271
) {
268
272
continue ;
@@ -364,14 +368,12 @@ function shouldIncludeNode(
364
368
variableValues : VariableValues ,
365
369
fragmentVariableValues : VariableValues | undefined ,
366
370
hideSuggestions : Maybe < boolean > ,
371
+ forbidSkipInclude : boolean ,
367
372
) : boolean {
368
373
const skipDirectiveNode = node . directives ?. find (
369
374
( directive ) => directive . name . value === GraphQLSkipDirective . name ,
370
375
) ;
371
- if (
372
- skipDirectiveNode &&
373
- variableValues === VALIDATION_PHASE_EMPTY_VARIABLES
374
- ) {
376
+ if ( skipDirectiveNode && forbidSkipInclude ) {
375
377
context . forbiddenDirectiveInstances . push ( skipDirectiveNode ) ;
376
378
return false ;
377
379
}
@@ -391,10 +393,7 @@ function shouldIncludeNode(
391
393
const includeDirectiveNode = node . directives ?. find (
392
394
( directive ) => directive . name . value === GraphQLIncludeDirective . name ,
393
395
) ;
394
- if (
395
- includeDirectiveNode &&
396
- variableValues === VALIDATION_PHASE_EMPTY_VARIABLES
397
- ) {
396
+ if ( includeDirectiveNode && forbidSkipInclude ) {
398
397
context . forbiddenDirectiveInstances . push ( includeDirectiveNode ) ;
399
398
return false ;
400
399
}
0 commit comments