Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6cc8044

Browse files
committed
@defer is now auto included in the schema if missing
1 parent 7f3326f commit 6cc8044

File tree

10 files changed

+131
-27
lines changed

10 files changed

+131
-27
lines changed

src/main/java/graphql/schema/GraphQLSchema.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,7 @@ private GraphQLSchema buildImpl() {
850850
addBuiltInDirective(Directives.DeprecatedDirective, additionalDirectives);
851851
addBuiltInDirective(Directives.SpecifiedByDirective, additionalDirectives);
852852
addBuiltInDirective(Directives.OneOfDirective, additionalDirectives);
853+
addBuiltInDirective(Directives.DeferDirective, additionalDirectives);
853854
addBuiltInDirective(Directives.ExperimentalDisableErrorPropagationDirective, additionalDirectives);
854855

855856
// quick build - no traversing

src/main/java/graphql/schema/idl/DirectiveInfo.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,6 @@
1515
@PublicApi
1616
public class DirectiveInfo {
1717

18-
/**
19-
* A set of directives which provided by graphql specification
20-
*/
21-
public static final Set<GraphQLDirective> GRAPHQL_SPECIFICATION_DIRECTIVES = ImmutableSet.of(
22-
Directives.IncludeDirective,
23-
Directives.SkipDirective,
24-
Directives.DeprecatedDirective,
25-
Directives.SpecifiedByDirective,
26-
Directives.OneOfDirective
27-
);
2818

2919
/**
3020
* A map from directive name to directive which provided by specification
@@ -37,8 +27,13 @@ public class DirectiveInfo {
3727
Directives.OneOfDirective.getName(), Directives.OneOfDirective,
3828
// technically this is NOT yet in spec - but it is added by default by graphql-java so we include it
3929
// we should also do @defer at some future time soon
30+
Directives.DeferDirective.getName(), Directives.DeferDirective,
4031
Directives.ExperimentalDisableErrorPropagationDirective.getName(), Directives.ExperimentalDisableErrorPropagationDirective
4132
);
33+
/**
34+
* A set of directives which provided by graphql specification
35+
*/
36+
public static final Set<GraphQLDirective> GRAPHQL_SPECIFICATION_DIRECTIVES =ImmutableSet.copyOf(GRAPHQL_SPECIFICATION_DIRECTIVE_MAP.values());
4237

4338
/**
4439
* Returns true if a directive with provided directiveName has been defined in graphql specification

src/test/groovy/graphql/Issue2141.groovy

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ class Issue2141 extends Specification {
2424
then:
2525
schemaStr == '''directive @auth(roles: [String!]) on FIELD_DEFINITION
2626
27+
"This directive allows results to be deferred during execution"
28+
directive @defer(
29+
"Deferred behaviour is controlled by this argument"
30+
if: Boolean! = true,
31+
"A unique label that represents the fragment being deferred"
32+
label: String
33+
) on FRAGMENT_SPREAD | INLINE_FRAGMENT
34+
2735
"Marks the field, argument, input field or enum value as deprecated"
2836
directive @deprecated(
2937
"The reason for the deprecation"

src/test/groovy/graphql/StarWarsIntrospectionTests.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,6 @@ class StarWarsIntrospectionTests extends Specification {
430430
schemaParts.get('mutationType').size() == 1
431431
schemaParts.get('subscriptionType') == null
432432
schemaParts.get('types').size() == 17
433-
schemaParts.get('directives').size() == 6
433+
schemaParts.get('directives').size() == 7
434434
}
435435
}

src/test/groovy/graphql/introspection/IntrospectionWithDirectivesSupportTest.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class IntrospectionWithDirectivesSupportTest extends Specification {
9292
schemaType["directives"] == [
9393
[name: "include"], [name: "skip"], [name: "example"], [name: "secret"],
9494
[name: "noDefault"], [name: "deprecated"], [name: "specifiedBy"], [name: "oneOf"],
95-
[name: "experimental_disableErrorPropagation"]
95+
[name: "defer"], [name: "experimental_disableErrorPropagation"]
9696
]
9797

9898
schemaType["appliedDirectives"] == [[name: "example", args: [[name: "argName", value: '"onSchema"']]]]
@@ -175,7 +175,7 @@ class IntrospectionWithDirectivesSupportTest extends Specification {
175175
def definedDirectives = er.data["__schema"]["directives"]
176176
// secret is filter out
177177
definedDirectives == [[name: "include"], [name: "skip"], [name: "example"], [name: "deprecated"], [name: "specifiedBy"], [name: "oneOf"],
178-
[name: "experimental_disableErrorPropagation"]
178+
[name: "defer"], [name: "experimental_disableErrorPropagation"]
179179
]
180180
}
181181

src/test/groovy/graphql/schema/GraphQLSchemaTest.groovy

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,22 +155,22 @@ class GraphQLSchemaTest extends Specification {
155155
when: "no additional directives have been specified"
156156
def schema = schemaBuilder.build()
157157
then:
158-
schema.directives.size() == 6
158+
schema.directives.size() == 7
159159

160160
when: "clear directives is called"
161161
schema = schemaBuilder.clearDirectives().build()
162162
then:
163-
schema.directives.size() == 4 // @deprecated and @specifiedBy and @oneOf et al is ALWAYS added if missing
163+
schema.directives.size() == 5 // @deprecated and @specifiedBy and @oneOf et al is ALWAYS added if missing
164164

165165
when: "clear directives is called with more directives"
166166
schema = schemaBuilder.clearDirectives().additionalDirective(Directives.SkipDirective).build()
167167
then:
168-
schema.directives.size() == 5
168+
schema.directives.size() == 6
169169

170170
when: "the schema is transformed, things are copied"
171171
schema = schema.transform({ builder -> builder.additionalDirective(Directives.IncludeDirective) })
172172
then:
173-
schema.directives.size() == 6
173+
schema.directives.size() == 7
174174
}
175175

176176
def "clear additional types works as expected"() {

src/test/groovy/graphql/schema/diffing/SchemaDiffingTest.groovy

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ class SchemaDiffingTest extends Specification {
3535
schemaGraph.getVerticesByType(SchemaGraph.UNION).size() == 0
3636
schemaGraph.getVerticesByType(SchemaGraph.SCALAR).size() == 2
3737
schemaGraph.getVerticesByType(SchemaGraph.FIELD).size() == 40
38-
schemaGraph.getVerticesByType(SchemaGraph.ARGUMENT).size() == 9
38+
schemaGraph.getVerticesByType(SchemaGraph.ARGUMENT).size() == 11
3939
schemaGraph.getVerticesByType(SchemaGraph.INPUT_FIELD).size() == 0
4040
schemaGraph.getVerticesByType(SchemaGraph.INPUT_OBJECT).size() == 0
41-
schemaGraph.getVerticesByType(SchemaGraph.DIRECTIVE).size() == 6
41+
schemaGraph.getVerticesByType(SchemaGraph.DIRECTIVE).size() == 7
4242
schemaGraph.getVerticesByType(SchemaGraph.APPLIED_ARGUMENT).size() == 0
4343
schemaGraph.getVerticesByType(SchemaGraph.APPLIED_DIRECTIVE).size() == 0
44-
schemaGraph.size() == 94
44+
schemaGraph.size() == 97
4545

4646
}
4747

src/test/groovy/graphql/schema/idl/SchemaGeneratorAppliedDirectiveHelperTest.groovy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class SchemaGeneratorAppliedDirectiveHelperTest extends Specification {
5555
schema.getDirectives().collect {it.name}.sort() == [
5656
"bar",
5757
"complex",
58+
"defer",
5859
"deprecated",
5960
"experimental_disableErrorPropagation",
6061
"foo",
@@ -106,6 +107,7 @@ class SchemaGeneratorAppliedDirectiveHelperTest extends Specification {
106107
schema.getDirectives().collect {it.name}.sort() == [
107108
"bar",
108109
"complex",
110+
"defer",
109111
"deprecated",
110112
"experimental_disableErrorPropagation",
111113
"foo",

src/test/groovy/graphql/schema/idl/SchemaGeneratorTest.groovy

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2025,10 +2025,11 @@ class SchemaGeneratorTest extends Specification {
20252025
directives = schema.getDirectives()
20262026
20272027
then:
2028-
directives.size() == 9 // built in ones : include / skip and deprecated
2028+
directives.size() == 10 // built in ones : include / skip and deprecated
20292029
def directiveNames = directives.collect { it.name }
20302030
directiveNames.contains("include")
20312031
directiveNames.contains("skip")
2032+
directiveNames.contains("defer")
20322033
directiveNames.contains("deprecated")
20332034
directiveNames.contains("specifiedBy")
20342035
directiveNames.contains("oneOf")
@@ -2040,9 +2041,10 @@ class SchemaGeneratorTest extends Specification {
20402041
directivesMap = schema.getDirectivesByName()
20412042
20422043
then:
2043-
directivesMap.size() == 9 // built in ones
2044+
directivesMap.size() == 10 // built in ones
20442045
directivesMap.containsKey("include")
20452046
directivesMap.containsKey("skip")
2047+
directivesMap.containsKey("defer")
20462048
directivesMap.containsKey("deprecated")
20472049
directivesMap.containsKey("oneOf")
20482050
directivesMap.containsKey("sd1")

src/test/groovy/graphql/schema/idl/SchemaPrinterTest.groovy

Lines changed: 101 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,14 @@ type Query {
965965
// args and directives are sorted like the rest of the schema printer
966966
result == '''directive @argDirective on ARGUMENT_DEFINITION
967967
968+
"This directive allows results to be deferred during execution"
969+
directive @defer(
970+
"Deferred behaviour is controlled by this argument"
971+
if: Boolean! = true,
972+
"A unique label that represents the fragment being deferred"
973+
label: String
974+
) on FRAGMENT_SPREAD | INLINE_FRAGMENT
975+
968976
"Marks the field, argument, input field or enum value as deprecated"
969977
directive @deprecated(
970978
"The reason for the deprecation"
@@ -1144,7 +1152,15 @@ input SomeInput {
11441152

11451153
then:
11461154
// args and directives are sorted like the rest of the schema printer
1147-
result == '''"Marks the field, argument, input field or enum value as deprecated"
1155+
result == '''"This directive allows results to be deferred during execution"
1156+
directive @defer(
1157+
"Deferred behaviour is controlled by this argument"
1158+
if: Boolean! = true,
1159+
"A unique label that represents the fragment being deferred"
1160+
label: String
1161+
) on FRAGMENT_SPREAD | INLINE_FRAGMENT
1162+
1163+
"Marks the field, argument, input field or enum value as deprecated"
11481164
directive @deprecated(
11491165
"The reason for the deprecation"
11501166
reason: String! = "No longer supported"
@@ -1243,7 +1259,15 @@ type Query {
12431259
def resultWithDirectives = new SchemaPrinter(defaultOptions().includeDirectives(true)).print(schema)
12441260

12451261
then:
1246-
resultWithDirectives == '''"Marks the field, argument, input field or enum value as deprecated"
1262+
resultWithDirectives == '''"This directive allows results to be deferred during execution"
1263+
directive @defer(
1264+
"Deferred behaviour is controlled by this argument"
1265+
if: Boolean! = true,
1266+
"A unique label that represents the fragment being deferred"
1267+
label: String
1268+
) on FRAGMENT_SPREAD | INLINE_FRAGMENT
1269+
1270+
"Marks the field, argument, input field or enum value as deprecated"
12471271
directive @deprecated(
12481272
"The reason for the deprecation"
12491273
reason: String! = "No longer supported"
@@ -1314,7 +1338,15 @@ type Query {
13141338
def resultWithDirectiveDefinitions = new SchemaPrinter(defaultOptions().includeDirectiveDefinitions(true)).print(schema)
13151339

13161340
then:
1317-
resultWithDirectiveDefinitions == '''"Marks the field, argument, input field or enum value as deprecated"
1341+
resultWithDirectiveDefinitions == '''"This directive allows results to be deferred during execution"
1342+
directive @defer(
1343+
"Deferred behaviour is controlled by this argument"
1344+
if: Boolean! = true,
1345+
"A unique label that represents the fragment being deferred"
1346+
label: String
1347+
) on FRAGMENT_SPREAD | INLINE_FRAGMENT
1348+
1349+
"Marks the field, argument, input field or enum value as deprecated"
13181350
directive @deprecated(
13191351
"The reason for the deprecation"
13201352
reason: String! = "No longer supported"
@@ -1414,6 +1446,14 @@ extend schema {
14141446
subscription: MySubscription
14151447
}
14161448
1449+
"This directive allows results to be deferred during execution"
1450+
directive @defer(
1451+
"Deferred behaviour is controlled by this argument"
1452+
if: Boolean! = true,
1453+
"A unique label that represents the fragment being deferred"
1454+
label: String
1455+
) on FRAGMENT_SPREAD | INLINE_FRAGMENT
1456+
14171457
"Marks the field, argument, input field or enum value as deprecated"
14181458
directive @deprecated(
14191459
"The reason for the deprecation"
@@ -1503,6 +1543,14 @@ schema @schemaDirective{
15031543
mutation: MyMutation
15041544
}
15051545
1546+
"This directive allows results to be deferred during execution"
1547+
directive @defer(
1548+
"Deferred behaviour is controlled by this argument"
1549+
if: Boolean! = true,
1550+
"A unique label that represents the fragment being deferred"
1551+
label: String
1552+
) on FRAGMENT_SPREAD | INLINE_FRAGMENT
1553+
15061554
"Marks the field, argument, input field or enum value as deprecated"
15071555
directive @deprecated(
15081556
"The reason for the deprecation"
@@ -1646,7 +1694,15 @@ type MyQuery {
16461694
def result = new SchemaPrinter(printOptions).print(schema)
16471695

16481696
then:
1649-
result == '''"Marks the field, argument, input field or enum value as deprecated"
1697+
result == '''"This directive allows results to be deferred during execution"
1698+
directive @defer(
1699+
"Deferred behaviour is controlled by this argument"
1700+
if: Boolean! = true,
1701+
"A unique label that represents the fragment being deferred"
1702+
label: String
1703+
) on FRAGMENT_SPREAD | INLINE_FRAGMENT
1704+
1705+
"Marks the field, argument, input field or enum value as deprecated"
16501706
directive @deprecated(
16511707
"The reason for the deprecation"
16521708
reason: String! = "No longer supported"
@@ -2185,6 +2241,14 @@ type PrintMeType {
21852241
query: MyQuery
21862242
}
21872243
2244+
"This directive allows results to be deferred during execution"
2245+
directive @defer(
2246+
"Deferred behaviour is controlled by this argument"
2247+
if: Boolean! = true,
2248+
"A unique label that represents the fragment being deferred"
2249+
label: String
2250+
) on FRAGMENT_SPREAD | INLINE_FRAGMENT
2251+
21882252
"Marks the field, argument, input field or enum value as deprecated"
21892253
directive @deprecated(
21902254
"The reason for the deprecation"
@@ -2429,6 +2493,14 @@ directive @deprecated(
24292493
reason: String! = "No longer supported"
24302494
) on FIELD_DEFINITION | ARGUMENT_DEFINITION | ENUM_VALUE | INPUT_FIELD_DEFINITION
24312495
2496+
"This directive allows results to be deferred during execution"
2497+
directive @defer(
2498+
"A unique label that represents the fragment being deferred"
2499+
label: String,
2500+
"Deferred behaviour is controlled by this argument"
2501+
if: Boolean! = true
2502+
) on FRAGMENT_SPREAD | INLINE_FRAGMENT
2503+
24322504
union ZUnion = XQuery | Query
24332505
24342506
scalar ZScalar
@@ -2539,6 +2611,14 @@ schema {
25392611
mutation: Mutation
25402612
}
25412613
2614+
"This directive allows results to be deferred during execution"
2615+
directive @defer(
2616+
"Deferred behaviour is controlled by this argument"
2617+
if: Boolean! = true,
2618+
"A unique label that represents the fragment being deferred"
2619+
label: String
2620+
) on FRAGMENT_SPREAD | INLINE_FRAGMENT
2621+
25422622
"Marks the field, argument, input field or enum value as deprecated"
25432623
directive @deprecated(
25442624
"The reason for the deprecation"
@@ -2779,6 +2859,14 @@ schema {
27792859
mutation: Mutation
27802860
}
27812861
2862+
"This directive allows results to be deferred during execution"
2863+
directive @defer(
2864+
"Deferred behaviour is controlled by this argument"
2865+
if: Boolean! = true,
2866+
"A unique label that represents the fragment being deferred"
2867+
label: String
2868+
) on FRAGMENT_SPREAD | INLINE_FRAGMENT
2869+
27822870
"Marks the field, argument, input field or enum value as deprecated"
27832871
directive @deprecated(
27842872
"The reason for the deprecation"
@@ -2970,7 +3058,15 @@ input Input {
29703058

29713059
expect: "has no skip definition"
29723060

2973-
result == """"Marks the field, argument, input field or enum value as deprecated"
3061+
result == """"This directive allows results to be deferred during execution"
3062+
directive @defer(
3063+
"Deferred behaviour is controlled by this argument"
3064+
if: Boolean! = true,
3065+
"A unique label that represents the fragment being deferred"
3066+
label: String
3067+
) on FRAGMENT_SPREAD | INLINE_FRAGMENT
3068+
3069+
"Marks the field, argument, input field or enum value as deprecated"
29743070
directive @deprecated(
29753071
"The reason for the deprecation"
29763072
reason: String! = "No longer supported"

0 commit comments

Comments
 (0)