It just boils down to create a GraphQLHttpServlet
and configure its context path. Under the cover , it uses auto-configuration GraphQLWebAutoConfiguration
to define a GraphQLHttpServlet
as a bean, and configure the context path to be /graphql
.
That means you can reference how GraphQLWebAutoConfiguration
does and create another GraphQLHttpServlet
instance that registered to other context path.
The main point is that to register a Servlet
in spring boot , you can simply create a ServletRegistrationBean
that wraps the HttpServlet
which you want to create .See docs for more details.
A simple example is :
@Bean
public ServletRegistrationBean<AbstractGraphQLHttpServlet> fooGraphQLServlet() {
//Create and configure the GraphQL Schema.
GraphQLSchema schema = xxxxxxx;
GraphQLHttpServlet graphQLHttpServlet = GraphQLHttpServlet.with(schema);
ServletRegistrationBean<AbstractGraphQLHttpServlet> registration = new ServletRegistrationBean<>(
graphQLHttpServlet, "/graphql2/*");
registration.setName("Another GraphQL Endpoint");
return registration;
}