We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9479cc0 commit 0a76c76Copy full SHA for 0a76c76
2 files changed
src/main/java/graphql/schema/idl/SchemaGeneratorHelper.java
@@ -80,8 +80,10 @@
80
81
import static graphql.Assert.assertNotNull;
82
import static graphql.Directives.DEPRECATED_DIRECTIVE_DEFINITION;
83
+import static graphql.Directives.IncludeDirective;
84
import static graphql.Directives.NO_LONGER_SUPPORTED;
85
import static graphql.Directives.SPECIFIED_BY_DIRECTIVE_DEFINITION;
86
+import static graphql.Directives.SkipDirective;
87
import static graphql.Directives.SpecifiedByDirective;
88
import static graphql.collect.ImmutableKit.emptyList;
89
import static graphql.introspection.Introspection.DirectiveLocation.ARGUMENT_DEFINITION;
@@ -1055,6 +1057,11 @@ Set<GraphQLDirective> buildAdditionalDirectiveDefinitions(BuildContext buildCtx)
1055
1057
TypeDefinitionRegistry typeRegistry = buildCtx.getTypeRegistry();
1056
1058
1059
for (DirectiveDefinition directiveDefinition : typeRegistry.getDirectiveDefinitions().values()) {
1060
+ if (IncludeDirective.getName().equals(directiveDefinition.getName())
1061
+ || SkipDirective.getName().equals(directiveDefinition.getName())) {
1062
+ // skip and include directives are added by default to the GraphQLSchema via the GraphQLSchema builder.
1063
+ continue;
1064
+ }
1065
GraphQLDirective directive = buildDirectiveDefinitionFromAst(buildCtx, directiveDefinition, inputTypeFactory(buildCtx));
1066
buildCtx.addDirectiveDefinition(directive);
1067
additionalDirectives.add(directive);
src/test/groovy/graphql/schema/idl/SchemaGeneratorTest.groovy
@@ -2533,4 +2533,35 @@ class SchemaGeneratorTest extends Specification {
2533
then:
2534
noExceptionThrown()
2535
}
2536
+
2537
+ def "skip and include should be added to the schema only if not already defined"() {
2538
+ def sdl = '''
2539
+ "Directs the executor to skip this field or fragment when the `if`'argument is true."
2540
+ directive @skip(
2541
+ "Skipped when true."
2542
+ if: Boolean!
2543
+ ) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
2544
2545
+ "Directs the executor to include this field or fragment only when the `if` argument is true"
2546
+ directive @include(
2547
+ "Included when true."
2548
2549
2550
2551
+ type Query {
2552
+ hello: String
2553
2554
+ '''
2555
+ when:
2556
+ def schema = TestUtil.schema(sdl)
2557
+ then:
2558
+ schema.getDirectives().findAll { it.name == "skip" }.size() == 1
2559
+ schema.getDirectives().findAll { it.name == "include" }.size() == 1
2560
2561
+ and:
2562
+ def newSchema = GraphQLSchema.newSchema(schema).build()
2563
2564
+ newSchema.getDirectives().findAll { it.name == "skip" }.size() == 1
2565
+ newSchema.getDirectives().findAll { it.name == "include" }.size() == 1
2566
2567
0 commit comments