Skip to content

Updating the README for corrected example for dataloader. #203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 25, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,28 +247,35 @@ public class CustomGraphQLContextBuilder implements GraphQLContextBuilder {
this.userDataLoader = userDataLoader;
}

@Override
public GraphQLContext build(HttpServletRequest req) {
return new GraphQLContext(buildDataLoaderRegistry());
}

@Override
public GraphQLContext build() {
return new GraphQLContext(buildDataLoaderRegistry());
return new DefaultGraphQLContext();
}

@Override
public GraphQLContext build(HandshakeRequest request) {
return new GraphQLContext(buildDataLoaderRegistry());
public GraphQLContext build(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
return DefaultGraphQLServletContext.createServletContext()
.with(httpServletRequest)
.with(httpServletResponse)
.with(buildDataLoaderRegistry())
.build();
}

public GraphQLContext build(Session session, HandshakeRequest handshakeRequest) {
return DefaultGraphQLWebSocketContext.createWebSocketContext()
.with(session)
.with(handshakeRequest)
.with(buildDataLoaderRegistry())
.build();
}

private DataLoaderRegistry buildDataLoaderRegistry() {
DataLoaderRegistry dataLoaderRegistry = new DataLoaderRegistry();
dataLoaderRegistry.register("userDataLoader", userDataLoader);
return dataLoaderRegistry;
DataLoaderRegistry registry = new DataLoaderRegistry();
for (BatchLoader batchLoader: this.batchLoaders) {
registry.register(batchLoader.getClass().getSimpleName(), DataLoader.newDataLoader(batchLoader));
}
return registry;
}
}

```
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:
```java
Expand Down