|
1 | 1 | package graphql; |
2 | 2 |
|
3 | 3 |
|
| 4 | +import graphql.language.BooleanValue; |
4 | 5 | import graphql.language.Description; |
5 | 6 | import graphql.language.DirectiveDefinition; |
6 | 7 | import graphql.language.StringValue; |
@@ -33,13 +34,21 @@ public class Directives { |
33 | 34 | private static final String SPECIFIED_BY = "specifiedBy"; |
34 | 35 | private static final String DEPRECATED = "deprecated"; |
35 | 36 | private static final String ONE_OF = "oneOf"; |
| 37 | + private static final String DEFER = "defer"; |
36 | 38 |
|
37 | 39 | public static final String NO_LONGER_SUPPORTED = "No longer supported"; |
38 | 40 | public static final DirectiveDefinition DEPRECATED_DIRECTIVE_DEFINITION; |
39 | 41 | public static final DirectiveDefinition SPECIFIED_BY_DIRECTIVE_DEFINITION; |
40 | 42 | @ExperimentalApi |
41 | 43 | public static final DirectiveDefinition ONE_OF_DIRECTIVE_DEFINITION; |
42 | 44 |
|
| 45 | + /** |
| 46 | + * The @defer directive can be used to defer sending data for a field till later in the query. This is an opt-in |
| 47 | + * directive that is not available unless it is explicitly put into the schema. |
| 48 | + */ |
| 49 | +// @ExperimentalApi |
| 50 | +// public static final DirectiveDefinition DEFER_DIRECTIVE_DEFINITION; |
| 51 | + |
43 | 52 |
|
44 | 53 | static { |
45 | 54 | DEPRECATED_DIRECTIVE_DEFINITION = DirectiveDefinition.newDirectiveDefinition() |
@@ -75,8 +84,56 @@ public class Directives { |
75 | 84 | .directiveLocation(newDirectiveLocation().name(INPUT_OBJECT.name()).build()) |
76 | 85 | .description(createDescription("Indicates an Input Object is a OneOf Input Object.")) |
77 | 86 | .build(); |
| 87 | + |
| 88 | +// DEFER_DIRECTIVE_DEFINITION = DirectiveDefinition.newDirectiveDefinition() |
| 89 | +// .name(DEFER) |
| 90 | +// .description(createDescription("This directive allows results to be deferred during execution")) |
| 91 | +// .directiveLocation(newDirectiveLocation().name(FRAGMENT_SPREAD.name()).build()) |
| 92 | +// .directiveLocation(newDirectiveLocation().name(INLINE_FRAGMENT.name()).build()) |
| 93 | +// .inputValueDefinition( |
| 94 | +// newInputValueDefinition() |
| 95 | +// .name("if") |
| 96 | +// .description(createDescription("Deferred behaviour is controlled by this argument")) |
| 97 | +// .type(newTypeName().name("Boolean").build()) |
| 98 | +// .defaultValue(BooleanValue.newBooleanValue(true).build()) |
| 99 | +// .build()) |
| 100 | +// .inputValueDefinition( |
| 101 | +// newInputValueDefinition() |
| 102 | +// // NOTE: as per the spec draft [https://github.com/graphql/graphql-spec/pull/742/files]: |
| 103 | +// // > `label` must not be provided as a variable. |
| 104 | +// // VALIDATION: the value of "label" MUST be unique across @defer and @stream in a query |
| 105 | +// .name("label") |
| 106 | +// .description(createDescription("A unique label that represents the fragment being deferred")) |
| 107 | +// .type(newTypeName().name("Boolean").build()) |
| 108 | +// .defaultValue(BooleanValue.newBooleanValue(true).build()) |
| 109 | +// .build()) |
| 110 | +// .build(); |
78 | 111 | } |
79 | 112 |
|
| 113 | + /** |
| 114 | + * The @defer directive can be used to defer sending data for a field till later in the query. This is an opt-in |
| 115 | + * directive that is not available unless it is explicitly put into the schema. |
| 116 | + */ |
| 117 | + public static final GraphQLDirective DeferDirective = GraphQLDirective.newDirective() |
| 118 | + .name("defer") |
| 119 | + .description("This directive allows results to be deferred during execution") |
| 120 | + .validLocations(FRAGMENT_SPREAD, INLINE_FRAGMENT) |
| 121 | + .argument(newArgument() |
| 122 | + .name("if") |
| 123 | + .type(nonNull(GraphQLBoolean)) |
| 124 | + .description("Deferred behaviour is controlled by this argument") |
| 125 | + .defaultValueLiteral(BooleanValue.newBooleanValue(true).build()) |
| 126 | + ) |
| 127 | + .argument(newArgument() |
| 128 | + // NOTE: as per the spec draft [https://github.com/graphql/graphql-spec/pull/742/files]: |
| 129 | + // > `label` must not be provided as a variable. |
| 130 | + // VALIDATION: the value of "label" MUST be unique across @defer and @stream in a query |
| 131 | + .name("label") |
| 132 | + .type(GraphQLString) |
| 133 | + .description("A unique label that represents the fragment being deferred") |
| 134 | + ) |
| 135 | + .build(); |
| 136 | + |
80 | 137 | public static final GraphQLDirective IncludeDirective = GraphQLDirective.newDirective() |
81 | 138 | .name("include") |
82 | 139 | .description("Directs the executor to include this field or fragment only when the `if` argument is true") |
|
0 commit comments