Skip to content
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

Ability to supply a different GraphQL java based upon the request context. #2680

Open
wants to merge 3 commits into
base: 4.x
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class GraphQLHandlerImpl implements GraphQLHandler {
private static final Function<RoutingContext, Locale> DEFAULT_LOCALE_FACTORY = rc -> null;

private final GraphQL graphQL;
private final Function<RoutingContext, Future<GraphQL>> graphQLFactory;
private final GraphQLHandlerOptions options;

private Function<RoutingContext, Object> queryContextFactory = DEFAULT_QUERY_CONTEXT_FACTORY;
Expand All @@ -65,6 +66,13 @@ public class GraphQLHandlerImpl implements GraphQLHandler {

public GraphQLHandlerImpl(GraphQL graphQL, GraphQLHandlerOptions options) {
this.graphQL = graphQL;
this.graphQLFactory = null;
this.options = options == null ? new GraphQLHandlerOptions() : options;
}

public GraphQLHandlerImpl(Function<RoutingContext, Future<GraphQL>> graphQLFactory, GraphQLHandlerOptions options) {
this.graphQL = null;
this.graphQLFactory = graphQLFactory;
this.options = options == null ? new GraphQLHandlerOptions() : options;
}

Expand Down Expand Up @@ -471,8 +479,18 @@ public ExecutionInput.Builder builder() {
});
}

return Future.fromCompletionStage(graphQL.executeAsync(builder.build()), rc.vertx().getOrCreateContext())
.map(executionResult -> new JsonObject(executionResult.toSpecification()));
if(graphQLFactory != null){
return graphQLFactory.apply(rc)
.compose(graphQL -> Future.fromCompletionStage(graphQL.executeAsync(builder.build()),
rc.vertx().getOrCreateContext())
.map(executionResult -> new JsonObject(executionResult.toSpecification())));
}else if(graphQL != null){
return Future.fromCompletionStage(graphQL.executeAsync(builder.build()), rc.vertx().getOrCreateContext())
.map(executionResult -> new JsonObject(executionResult.toSpecification()));
}else{
// should never happen
throw new IllegalStateException("GraphQL not configured");
}
}

private String getContentType(RoutingContext rc) {
Expand Down