Skip to content

Commit 39d105d

Browse files
committed
Add missing directive definitions
1 parent 99ec596 commit 39d105d

File tree

1 file changed

+67
-7
lines changed

1 file changed

+67
-7
lines changed

src/main/java/graphql/Directives.java

Lines changed: 67 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,25 @@
3131
@PublicApi
3232
public class Directives {
3333

34-
private static final String SPECIFIED_BY = "specifiedBy";
3534
private static final String DEPRECATED = "deprecated";
35+
private static final String INCLUDE = "include";
36+
private static final String SKIP = "skip";
37+
private static final String SPECIFIED_BY = "specifiedBy";
3638
private static final String ONE_OF = "oneOf";
3739
private static final String DEFER = "defer";
3840

39-
public static final String NO_LONGER_SUPPORTED = "No longer supported";
4041
public static final DirectiveDefinition DEPRECATED_DIRECTIVE_DEFINITION;
42+
public static final DirectiveDefinition INCLUDE_DIRECTIVE_DEFINITION;
43+
public static final DirectiveDefinition SKIP_DIRECTIVE_DEFINITION;
4144
public static final DirectiveDefinition SPECIFIED_BY_DIRECTIVE_DEFINITION;
4245
@ExperimentalApi
4346
public static final DirectiveDefinition ONE_OF_DIRECTIVE_DEFINITION;
47+
@ExperimentalApi
48+
public static final DirectiveDefinition DEFER_DIRECTIVE_DEFINITION;
49+
50+
public static final String BOOLEAN = "Boolean";
51+
public static final String STRING = "String";
52+
public static final String NO_LONGER_SUPPORTED = "No longer supported";
4453

4554
static {
4655
DEPRECATED_DIRECTIVE_DEFINITION = DirectiveDefinition.newDirectiveDefinition()
@@ -54,11 +63,39 @@ public class Directives {
5463
newInputValueDefinition()
5564
.name("reason")
5665
.description(createDescription("The reason for the deprecation"))
57-
.type(newTypeName().name("String").build())
66+
.type(newTypeName().name(STRING).build())
5867
.defaultValue(StringValue.newStringValue().value(NO_LONGER_SUPPORTED).build())
5968
.build())
6069
.build();
6170

71+
INCLUDE_DIRECTIVE_DEFINITION = DirectiveDefinition.newDirectiveDefinition()
72+
.name(INCLUDE)
73+
.directiveLocation(newDirectiveLocation().name(FRAGMENT_SPREAD.name()).build())
74+
.directiveLocation(newDirectiveLocation().name(INLINE_FRAGMENT.name()).build())
75+
.directiveLocation(newDirectiveLocation().name(FIELD.name()).build())
76+
.description(createDescription("Directs the executor to include this field or fragment only when the `if` argument is true"))
77+
.inputValueDefinition(
78+
newInputValueDefinition()
79+
.name("if")
80+
.description(createDescription("Included when true."))
81+
.type(newNonNullType(newTypeName().name(BOOLEAN).build()).build())
82+
.build())
83+
.build();
84+
85+
SKIP_DIRECTIVE_DEFINITION = DirectiveDefinition.newDirectiveDefinition()
86+
.name(SKIP)
87+
.directiveLocation(newDirectiveLocation().name(FRAGMENT_SPREAD.name()).build())
88+
.directiveLocation(newDirectiveLocation().name(INLINE_FRAGMENT.name()).build())
89+
.directiveLocation(newDirectiveLocation().name(FIELD.name()).build())
90+
.description(createDescription("Directs the executor to skip this field or fragment when the `if` argument is true."))
91+
.inputValueDefinition(
92+
newInputValueDefinition()
93+
.name("if")
94+
.description(createDescription("Skipped when true."))
95+
.type(newNonNullType(newTypeName().name(BOOLEAN).build()).build())
96+
.build())
97+
.build();
98+
6299
SPECIFIED_BY_DIRECTIVE_DEFINITION = DirectiveDefinition.newDirectiveDefinition()
63100
.name(SPECIFIED_BY)
64101
.directiveLocation(newDirectiveLocation().name(SCALAR.name()).build())
@@ -67,7 +104,7 @@ public class Directives {
67104
newInputValueDefinition()
68105
.name("url")
69106
.description(createDescription("The URL that specifies the behaviour of this scalar."))
70-
.type(newNonNullType(newTypeName().name("String").build()).build())
107+
.type(newNonNullType(newTypeName().name(STRING).build()).build())
71108
.build())
72109
.build();
73110

@@ -76,6 +113,26 @@ public class Directives {
76113
.directiveLocation(newDirectiveLocation().name(INPUT_OBJECT.name()).build())
77114
.description(createDescription("Indicates an Input Object is a OneOf Input Object."))
78115
.build();
116+
117+
DEFER_DIRECTIVE_DEFINITION = DirectiveDefinition.newDirectiveDefinition()
118+
.name(DEFER)
119+
.directiveLocation(newDirectiveLocation().name(FRAGMENT_SPREAD.name()).build())
120+
.directiveLocation(newDirectiveLocation().name(INLINE_FRAGMENT.name()).build())
121+
.description(createDescription("This directive allows results to be deferred during execution"))
122+
.inputValueDefinition(
123+
newInputValueDefinition()
124+
.name("if")
125+
.description(createDescription("Deferred behaviour is controlled by this argument"))
126+
.type(newNonNullType(newTypeName().name(BOOLEAN).build()).build())
127+
.defaultValue(BooleanValue.newBooleanValue(true).build())
128+
.build())
129+
.inputValueDefinition(
130+
newInputValueDefinition()
131+
.name("label")
132+
.description(createDescription("A unique label that represents the fragment being deferred"))
133+
.type(newTypeName().name(STRING).build())
134+
.build())
135+
.build();
79136
}
80137

81138
/**
@@ -104,33 +161,36 @@ public class Directives {
104161
.type(GraphQLString)
105162
.description("A unique label that represents the fragment being deferred")
106163
)
164+
.definition(DEFER_DIRECTIVE_DEFINITION)
107165
.build();
108166

109167
public static final GraphQLDirective IncludeDirective = GraphQLDirective.newDirective()
110-
.name("include")
168+
.name(INCLUDE)
111169
.description("Directs the executor to include this field or fragment only when the `if` argument is true")
112170
.argument(newArgument()
113171
.name("if")
114172
.type(nonNull(GraphQLBoolean))
115173
.description("Included when true."))
116174
.validLocations(FRAGMENT_SPREAD, INLINE_FRAGMENT, FIELD)
175+
.definition(INCLUDE_DIRECTIVE_DEFINITION)
117176
.build();
118177

119178
public static final GraphQLDirective SkipDirective = GraphQLDirective.newDirective()
120-
.name("skip")
179+
.name(SKIP)
121180
.description("Directs the executor to skip this field or fragment when the `if` argument is true.")
122181
.argument(newArgument()
123182
.name("if")
124183
.type(nonNull(GraphQLBoolean))
125184
.description("Skipped when true."))
126185
.validLocations(FRAGMENT_SPREAD, INLINE_FRAGMENT, FIELD)
186+
.definition(SKIP_DIRECTIVE_DEFINITION)
127187
.build();
128188

129189

130190
/**
131191
* The "deprecated" directive is special and is always available in a graphql schema
132192
* <p>
133-
* See https://graphql.github.io/graphql-spec/June2018/#sec--deprecated
193+
* See <a href="https://spec.graphql.org/draft/#sec--deprecated">the GraphQL specification for @deprecated</a>
134194
*/
135195
public static final GraphQLDirective DeprecatedDirective = GraphQLDirective.newDirective()
136196
.name(DEPRECATED)

0 commit comments

Comments
 (0)