Skip to content

Commit cf922e4

Browse files
authored
Merge pull request #203 from abhi-rao/#202
Updating the README for corrected example for dataloader.
2 parents 3ec69c1 + 22548f9 commit cf922e4

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

README.md

+20-13
Original file line numberDiff line numberDiff line change
@@ -247,28 +247,35 @@ public class CustomGraphQLContextBuilder implements GraphQLContextBuilder {
247247
this.userDataLoader = userDataLoader;
248248
}
249249

250-
@Override
251-
public GraphQLContext build(HttpServletRequest req) {
252-
return new GraphQLContext(buildDataLoaderRegistry());
253-
}
254250

255-
@Override
256251
public GraphQLContext build() {
257-
return new GraphQLContext(buildDataLoaderRegistry());
252+
return new DefaultGraphQLContext();
258253
}
259254

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();
263269
}
264270

265271
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;
269277
}
270278
}
271-
272279
```
273280
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:
274281
```java

0 commit comments

Comments
 (0)