@@ -247,28 +247,35 @@ public class CustomGraphQLContextBuilder implements GraphQLContextBuilder {
247
247
this . userDataLoader = userDataLoader;
248
248
}
249
249
250
- @Override
251
- public GraphQLContext build (HttpServletRequest req ) {
252
- return new GraphQLContext (buildDataLoaderRegistry());
253
- }
254
250
255
- @Override
256
251
public GraphQLContext build () {
257
- return new GraphQLContext (buildDataLoaderRegistry() );
252
+ return new DefaultGraphQLContext ( );
258
253
}
259
254
260
- @Override
261
- public GraphQLContext build (HandshakeRequest request ) {
262
- return new GraphQLContext (buildDataLoaderRegistry());
255
+ public GraphQLContext build (HttpServletRequest httpServletRequest , HttpServletResponse httpServletResponse ) {
256
+ return DefaultGraphQLServletContext . createServletContext()
257
+ .with(httpServletRequest)
258
+ .with(httpServletResponse)
259
+ .with(buildDataLoaderRegistry())
260
+ .build();
261
+ }
262
+
263
+ public GraphQLContext build (Session session , HandshakeRequest handshakeRequest ) {
264
+ return DefaultGraphQLWebSocketContext . createWebSocketContext()
265
+ .with(session)
266
+ .with(handshakeRequest)
267
+ .with(buildDataLoaderRegistry())
268
+ .build();
263
269
}
264
270
265
271
private DataLoaderRegistry buildDataLoaderRegistry () {
266
- DataLoaderRegistry dataLoaderRegistry = new DataLoaderRegistry ();
267
- dataLoaderRegistry. register(" userDataLoader" , userDataLoader);
268
- return dataLoaderRegistry;
272
+ DataLoaderRegistry registry = new DataLoaderRegistry ();
273
+ for (BatchLoader batchLoader: this . batchLoaders) {
274
+ registry. register(batchLoader. getClass(). getSimpleName(), DataLoader . newDataLoader(batchLoader));
275
+ }
276
+ return registry;
269
277
}
270
278
}
271
-
272
279
```
273
280
It is then possible to access the [ DataLoader] ( https://github.com/graphql-java/java-dataloader/blob/master/src/main/java/org/dataloader/DataLoader.java ) in the resolvers by accessing the [ DataLoaderRegistry] from context. For eg:
274
281
``` java
0 commit comments