Reputation: 805
Currently trying to setup SpringBoot and GraphQL but whenever I run the application I don't seem to get the /graphql endpoint exposed, nor does the graphiql UI get exposed when I set it to enabled in the application.yml file.
I've also tried setting the endpoint manually in the properties but that also isn't exposed.
I've pushed up the code to github below as I can't work out where the problem would be.
https://github.com/RyanMoss96/spring-boot-graphql
Upvotes: 3
Views: 3974
Reputation: 61
I wrote below code by manually registering servlet and it worked.
@Bean
public ServletRegistrationBean<AbstractGraphQLHttpServlet> defaultGraphQLServlet() throws IOException {
//Create and configure the GraphQL Schema.
List<String> sdlList = ReadUtils.readResources(this.getClass().getClassLoader(), "graphql", "graphql");
GraphQLSchema schema = buildSchema(sdlList);
GraphQLHttpServlet graphQLHttpServlet = GraphQLHttpServlet.with(schema);
ServletRegistrationBean<AbstractGraphQLHttpServlet> registration =
new ServletRegistrationBean<>(graphQLHttpServlet, "/graphql/*");
registration.setName("Default GraphQL Endpoint");
return registration;
}
Upvotes: 0
Reputation: 801
I think you need to downgrade the version. If you're using Spring Boot, use 2.7.x. It may work
Upvotes: 1
Reputation: 428
In my case, I had a typo in my GraphQL schema file name: its .graphqls
not .graphql
. Spring did not discover it and therefore not expose it automatically.
Upvotes: 0
Reputation: 9
graphql.servlet.mapping=/graphql
Add this information to application.yaml
Upvotes: 0