Skip to content

Commit 83384ec

Browse files
committed
readme update for settings
1 parent 6499056 commit 83384ec

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

README.md

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,8 @@ Here's an example of a GraphQL provider that implements three interfaces at the
234234

235235
## Request-scoped DataLoaders
236236

237-
It is possible to use dataloaders in a request scope by customizing [GraphQLContextBuilder](https://github.com/graphql-java-kickstart/graphql-java-servlet/blob/master/src/main/java/graphql/servlet/GraphQLContextBuilder.java).
238-
And instantiating a new [DataLoaderRegistry](https://github.com/graphql-java/java-dataloader/blob/master/src/main/java/org/dataloader/DataLoaderRegistry.java) for each GraphQLContext.
237+
It is possible to use dataloaders in both a request scope and a per query scope by customizing [GraphQLContextBuilder](https://github.com/graphql-java-kickstart/graphql-java-servlet/blob/master/src/main/java/graphql/servlet/context/GraphQLContextBuilder.java) and selecting the appropriate [ContextSetting](https://github.com/graphql-java-kickstart/graphql-java-servlet/blob/master/src/main/java/graphql/servlet/context/ContextSetting.java) with the provided [GraphQLConfiguration](https://github.com/graphql-java-kickstart/graphql-java-servlet/blob/master/src/main/java/graphql/servlet/config/GraphQLConfiguration.java).
238+
A new [DataLoaderRegistry](https://github.com/graphql-java/java-dataloader/blob/master/src/main/java/org/dataloader/DataLoaderRegistry.java) should be created in each call to the GraphQLContextBuilder, and the servlet will call the builder at the appropriate times.
239239
For eg:
240240
```java
241241
public class CustomGraphQLContextBuilder implements GraphQLContextBuilder {
@@ -248,26 +248,17 @@ public class CustomGraphQLContextBuilder implements GraphQLContextBuilder {
248248

249249
@Override
250250
public GraphQLContext build(HttpServletRequest req) {
251-
GraphQLContext context = new GraphQLContext(req);
252-
context.setDataLoaderRegistry(buildDataLoaderRegistry());
253-
254-
return context;
251+
return new GraphQLContext(buildDataLoaderRegistry());
255252
}
256253

257254
@Override
258255
public GraphQLContext build() {
259-
GraphQLContext context = new GraphQLContext();
260-
context.setDataLoaderRegistry(buildDataLoaderRegistry());
261-
262-
return context;
256+
return new GraphQLContext(buildDataLoaderRegistry());
263257
}
264258

265259
@Override
266260
public GraphQLContext build(HandshakeRequest request) {
267-
GraphQLContext context = new GraphQLContext(request);
268-
context.setDataLoaderRegistry(buildDataLoaderRegistry());
269-
270-
return context;
261+
return new GraphQLContext(buildDataLoaderRegistry());
271262
}
272263

273264
private DataLoaderRegistry buildDataLoaderRegistry() {
@@ -289,3 +280,4 @@ public class CustomGraphQLContextBuilder implements GraphQLContextBuilder {
289280
}
290281

291282
```
283+
If per request is selected, this will cause all queries within the http request, if using a batch, to share dataloader caches and batch together load calls as efficently as possible. The dataloaders are dispatched using instrumentation and the correct instrumentation will be selected according to the ContextSetting. The default context setting in GraphQLConfiguration is per query.

0 commit comments

Comments
 (0)