xiimoss
xiimoss

Reputation: 805

SpringBoot GraphQL Not exposing /graphql endpoint

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

Answers (4)

Rajesh B
Rajesh B

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

Rasathurai Karan
Rasathurai Karan

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

luke8800gts
luke8800gts

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

zhassurbek
zhassurbek

Reputation: 9

graphql.servlet.mapping=/graphql

Add this information to application.yaml

Upvotes: 0

Related Questions