@@ -22,11 +22,15 @@ import {
22
22
GraphQLObjectType ,
23
23
GraphQLScalarType ,
24
24
} from '../../type/definition.js' ;
25
- import { GraphQLString } from '../../type/scalars.js' ;
25
+ import { GraphQLBoolean , GraphQLString } from '../../type/scalars.js' ;
26
26
import { GraphQLSchema } from '../../type/schema.js' ;
27
27
28
28
import { executeSync } from '../execute.js' ;
29
29
import { getVariableValues } from '../values.js' ;
30
+ import { GraphQLSkipDirective } from '../../type/directives.js' ;
31
+ import { GraphQLIncludeDirective } from '../../type/directives.js' ;
32
+ import { GraphQLDirective } from '../../type/directives.js' ;
33
+ import { DirectiveLocation } from '../../language/directiveLocation.js' ;
30
34
31
35
const TestFaultyScalarGraphQLError = new GraphQLError (
32
36
'FaultyScalarErrorMessage' ,
@@ -154,7 +158,30 @@ const TestType = new GraphQLObjectType({
154
158
} ,
155
159
} ) ;
156
160
157
- const schema = new GraphQLSchema ( { query : TestType } ) ;
161
+ const schema = new GraphQLSchema ( {
162
+ query : TestType ,
163
+ directives : [
164
+ new GraphQLDirective ( {
165
+ name : 'skip' ,
166
+ description :
167
+ 'Directs the executor to skip this field or fragment when the `if` argument is true.' ,
168
+ locations : [
169
+ DirectiveLocation . FIELD ,
170
+ DirectiveLocation . FRAGMENT_SPREAD ,
171
+ DirectiveLocation . INLINE_FRAGMENT ,
172
+ ] ,
173
+ args : {
174
+ if : {
175
+ type : new GraphQLNonNull ( GraphQLBoolean ) ,
176
+ description : 'Skipped when true.' ,
177
+ // default values will override operation variables in the setting of defined fragment variables that are not provided
178
+ defaultValue : true ,
179
+ } ,
180
+ } ,
181
+ } ) ,
182
+ GraphQLIncludeDirective ,
183
+ ] ,
184
+ } ) ;
158
185
159
186
function executeQuery (
160
187
query : string ,
@@ -1434,5 +1461,33 @@ describe('Execute: Handles inputs', () => {
1434
1461
} ,
1435
1462
} ) ;
1436
1463
} ) ;
1464
+
1465
+ it ( 'when argument passed to a directive' , ( ) => {
1466
+ const result = executeQueryWithFragmentArguments ( `
1467
+ query {
1468
+ ...a(value: true)
1469
+ }
1470
+ fragment a($value: Boolean!) on TestType {
1471
+ fieldWithNonNullableStringInput @skip(if: $value)
1472
+ }
1473
+ ` ) ;
1474
+ expect ( result ) . to . deep . equal ( {
1475
+ data : { } ,
1476
+ } ) ;
1477
+ } ) ;
1478
+
1479
+ it ( 'when a nullable argument to a directive with a field default is not provided and shadowed by an operation variable' , ( ) => {
1480
+ const result = executeQueryWithFragmentArguments ( `
1481
+ query($value: Boolean) {
1482
+ ...a
1483
+ }
1484
+ fragment a($value: Boolean) on TestType {
1485
+ fieldWithNonNullableStringInput @skip(if: $value)
1486
+ }
1487
+ ` ) ;
1488
+ expect ( result ) . to . deep . equal ( {
1489
+ data : { } ,
1490
+ } ) ;
1491
+ } ) ;
1437
1492
} ) ;
1438
1493
} ) ;
0 commit comments