You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit af95e79
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: content/tools/directives/index.md
+5-4Lines changed: 5 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -68,9 +68,12 @@ Arguments the SDL leaves out are filled in with their default from the directive
68
68
69
69
An enum that's only used by directive definitions doesn't need a Java class. Its values are then passed to the wiring as `String`s. Add the enum to the [type dictionary]({{< relref "/tools/schema-definition/index.md#type-dictionary" >}}) to get the enum constants instead.
70
70
71
+
Wirings run once the whole schema is built, like in graphql-java, so the types they see are the real ones and not `GraphQLTypeReference`s.
72
+
71
73
## Supported locations
72
-
Support for directives is currently limited to the following locations:
74
+
Wirings run for directives on the following locations:
73
75
76
+
*`SCALAR`
74
77
*`OBJECT`
75
78
*`FIELD_DEFINITION`
76
79
*`ARGUMENT_DEFINITION`
@@ -81,8 +84,6 @@ Support for directives is currently limited to the following locations:
81
84
*`INPUT_OBJECT`
82
85
*`INPUT_FIELD_DEFINITION`
83
86
84
-
Meaning directives for the following locations are currently not yet supported:
85
-
86
-
*`SCALAR`
87
+
A directive applied where its definition doesn't allow it, without a required argument, or more than once without being `repeatable` logs a warning. These will fail the build in 15.0.0.
87
88
88
89
Directives on `schema` and `extend schema` don't run a wiring, but they're added to the schema's applied directives. Like everywhere else, they have to be declared, unless `allowUndeclaredDirectives` is set in the [schema parser options]({{< relref "/tools/schema-parser-options/index.md" >}}).
Copy file name to clipboardExpand all lines: content/tools/schema-definition/index.md
+18-9Lines changed: 18 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -108,7 +108,8 @@ class BookResolver implements GraphQLResolver<Book> /* This class is a resolver
108
108
109
109
When given a `BookResolver` instance, GraphQL Java Tools first attempts to map fields to methods on the resolver before mapping them to fields or methods on the data class.
110
110
If there is a matching method on the resolver, the data class instance is passed as the first argument to the resolver function. This does not apply to root resolvers, since those don't have a data class to resolve for.
111
-
An optional parameter can be defined to inject the `DataFetchingEnvironment`, and must be the last argument.
111
+
The field's arguments come next, in order.
112
+
After them, a method can take any of `DataFetchingEnvironment`, `GraphQLContext` and the `contextClass` set in the [schema parser options]({{< relref "/tools/schema-parser-options/index.md" >}}), in any order.
112
113
113
114
A resolver also applies to subclasses and implementations of its data class, so a `GraphQLResolver<Base>` resolves fields for a data class `Thing extends Base`.
114
115
A resolver for a generic class, like `GraphQLResolver<Page<?>>`, applies to every `Page<T>`.
@@ -150,24 +151,32 @@ SchemaParser.newParser()
150
151
151
152
The field mapping is done by name against public/protected methods and public/protected/private fields, with the following priority:
152
153
154
+
`*environmentOrContext` stands for any of `DataFetchingEnvironment`, `GraphQLContext` and the `contextClass`, in any order.
155
+
153
156
First on the resolver or root resolver (note that dataClassInstance doesn't apply for root resolvers):
Last of all, if the data class implements`java.util.Map` then:
169
172
1.`method get(name)`
170
173
174
+
If nothing above matches, a resolver method can leave out the data class instance, as long as it ends in at least one environment or context parameter:
175
+
176
+
1.`method <name>(*fieldArgs, *environmentOrContext)`, and the `is`, `get` and `getField` forms in the same order as above
177
+
178
+
This is for fields that only need the environment, e.g. a value the parent field put in its `localContext`. It doesn't apply when `allowUnimplementedResolvers` or a missing resolver data fetcher is set, since those already handle a field with no match.
179
+
171
180
172
181
<!--*Note:* `java.util.Optional` can be used for nullable field arguments and nullable return values, and the schema parser will verify that it's not used with non-null field arguments and return values.-->
Copy file name to clipboardExpand all lines: content/tools/schema-parser-options/index.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,6 +24,8 @@ Options:
24
24
```
25
25
* `genericWrappers`:Allows defining your own generic classes that should be unwrapped when matching Java types to GraphQL types. You must supply the classand the index (zero-indexed) of the wrapped generic type. For example: If you want to unwrap type argument `T` of `Future<T>`, you must pass `Future.class` and `0`.
26
26
Use `GenericWrapper.withTransformer` to also convert the value at runtime. If the transformer returns `null`, the field is `null`.
27
+
Wrappers and futures nested in lists or in other wrappers are unwrapped too, e.g. `List<Try<Payload>>` or `List<CompletableFuture<Item>>`. If one element fails, the whole field fails.
28
+
A transformer or nested future that calls a DataLoader after an async step needs graphql-java's DataLoader chaining (`DataLoaderDispatchingContextKeys.setEnableDataLoaderChaining`), otherwise the field never completes.
27
29
28
30
* `useDefaultGenericWrappers`: Defaults to `true`. Tells the parser whether or not to add it's own list of well-known generic wrappers, such as `Future` and `CompletableFuture`.
29
31
graphql-java only waits on a `CompletionStage`, so a method declared to return a `Future` has to return one, such as a `CompletableFuture`. Any other future fails the field with an error, unless a generic wrapper transformer converts it.
0 commit comments