You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The present hello world documentation does provide for starting GraphQL in Dropwizard But if we need to write REST and GraphQL APIs in the same Dropwizard application then we may need to look into the source code and tweak according to it.
Couple of tweaks which would help to expose both GraphQL and REST API endpoints simultaneously.
We have to change the root path in the GraphQL bundle which we add in the initialize method.
We have to also change the environment variables in run function in the GraphQL bundle class so that the GraphQL playground could find the schema.json file.
We have to override these methods in the main class of the Dropwizard app.
Now the changed versions of these methods will be :
@Override
public void initialize(Bootstrap<?> bootstrap) {
bootstrap.addBundle(new AssetsBundle("/assets", "/graphql", "index.htm", "graphql-playground"));
} // for exposing graphql endpoint at localhost:8080/graphql
@Override
public void run(final C configuration, final Environment environment) throws Exception {
final GraphQLFactory factory = getGraphQLFactory(configuration);
final PreparsedDocumentProvider provider =
new CachingPreparsedDocumentProvider(factory.getQueryCache(), environment.metrics());
final GraphQLSchema schema = factory.build();
final GraphQLQueryInvoker queryInvoker =
GraphQLQueryInvoker.newBuilder()
.withPreparsedDocumentProvider(provider)
.withInstrumentation(factory.getInstrumentations())
.build();
final graphql.kickstart.servlet.GraphQLConfiguration config =
graphql.kickstart.servlet.GraphQLConfiguration.with(schema).with(queryInvoker).build();
final GraphQLHttpServlet servlet = GraphQLHttpServlet.with(config);
environment.servlets().addServlet("graphql", servlet).addMapping("/schema", "/schema.json");
// for exposing the graphql schema at localhost:8080/graphql/schema
I found these tweaks useful for exposing REST and GraphQL APIs simultaneously. Raising this issue so that it would be helpful for those who would be facing the same issue. Adding these tweaks in the docs would be really helpful for someone who would want to try out GraphQL in Dropwizard.
The text was updated successfully, but these errors were encountered:
The present hello world documentation does provide for starting GraphQL in Dropwizard But if we need to write REST and GraphQL APIs in the same Dropwizard application then we may need to look into the source code and tweak according to it.
Couple of tweaks which would help to expose both GraphQL and REST API endpoints simultaneously.
We have to override these methods in the main class of the Dropwizard app.
Now the changed versions of these methods will be :
I found these tweaks useful for exposing REST and GraphQL APIs simultaneously. Raising this issue so that it would be helpful for those who would be facing the same issue. Adding these tweaks in the docs would be really helpful for someone who would want to try out GraphQL in Dropwizard.
The text was updated successfully, but these errors were encountered: