31
31
@ PublicApi
32
32
public class Directives {
33
33
34
- private static final String SPECIFIED_BY = "specifiedBy" ;
35
34
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" ;
36
38
private static final String ONE_OF = "oneOf" ;
37
39
private static final String DEFER = "defer" ;
38
40
39
- public static final String NO_LONGER_SUPPORTED = "No longer supported" ;
40
41
public static final DirectiveDefinition DEPRECATED_DIRECTIVE_DEFINITION ;
42
+ public static final DirectiveDefinition INCLUDE_DIRECTIVE_DEFINITION ;
43
+ public static final DirectiveDefinition SKIP_DIRECTIVE_DEFINITION ;
41
44
public static final DirectiveDefinition SPECIFIED_BY_DIRECTIVE_DEFINITION ;
42
45
@ ExperimentalApi
43
46
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" ;
44
53
45
54
static {
46
55
DEPRECATED_DIRECTIVE_DEFINITION = DirectiveDefinition .newDirectiveDefinition ()
@@ -54,11 +63,39 @@ public class Directives {
54
63
newInputValueDefinition ()
55
64
.name ("reason" )
56
65
.description (createDescription ("The reason for the deprecation" ))
57
- .type (newTypeName ().name ("String" ).build ())
66
+ .type (newTypeName ().name (STRING ).build ())
58
67
.defaultValue (StringValue .newStringValue ().value (NO_LONGER_SUPPORTED ).build ())
59
68
.build ())
60
69
.build ();
61
70
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
+
62
99
SPECIFIED_BY_DIRECTIVE_DEFINITION = DirectiveDefinition .newDirectiveDefinition ()
63
100
.name (SPECIFIED_BY )
64
101
.directiveLocation (newDirectiveLocation ().name (SCALAR .name ()).build ())
@@ -67,7 +104,7 @@ public class Directives {
67
104
newInputValueDefinition ()
68
105
.name ("url" )
69
106
.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 ())
71
108
.build ())
72
109
.build ();
73
110
@@ -76,6 +113,26 @@ public class Directives {
76
113
.directiveLocation (newDirectiveLocation ().name (INPUT_OBJECT .name ()).build ())
77
114
.description (createDescription ("Indicates an Input Object is a OneOf Input Object." ))
78
115
.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 ();
79
136
}
80
137
81
138
/**
@@ -104,33 +161,36 @@ public class Directives {
104
161
.type (GraphQLString )
105
162
.description ("A unique label that represents the fragment being deferred" )
106
163
)
164
+ .definition (DEFER_DIRECTIVE_DEFINITION )
107
165
.build ();
108
166
109
167
public static final GraphQLDirective IncludeDirective = GraphQLDirective .newDirective ()
110
- .name ("include" )
168
+ .name (INCLUDE )
111
169
.description ("Directs the executor to include this field or fragment only when the `if` argument is true" )
112
170
.argument (newArgument ()
113
171
.name ("if" )
114
172
.type (nonNull (GraphQLBoolean ))
115
173
.description ("Included when true." ))
116
174
.validLocations (FRAGMENT_SPREAD , INLINE_FRAGMENT , FIELD )
175
+ .definition (INCLUDE_DIRECTIVE_DEFINITION )
117
176
.build ();
118
177
119
178
public static final GraphQLDirective SkipDirective = GraphQLDirective .newDirective ()
120
- .name ("skip" )
179
+ .name (SKIP )
121
180
.description ("Directs the executor to skip this field or fragment when the `if` argument is true." )
122
181
.argument (newArgument ()
123
182
.name ("if" )
124
183
.type (nonNull (GraphQLBoolean ))
125
184
.description ("Skipped when true." ))
126
185
.validLocations (FRAGMENT_SPREAD , INLINE_FRAGMENT , FIELD )
186
+ .definition (SKIP_DIRECTIVE_DEFINITION )
127
187
.build ();
128
188
129
189
130
190
/**
131
191
* The "deprecated" directive is special and is always available in a graphql schema
132
192
* <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>
134
194
*/
135
195
public static final GraphQLDirective DeprecatedDirective = GraphQLDirective .newDirective ()
136
196
.name (DEPRECATED )
0 commit comments