javaspring-bootgraphqlspring-graphql

GraphQL error : Method not allowed error for GraphQL requests with Spring 3.1.1


I have upgraded spring boot to 3.1.1 and I am getting 405 method not allowed for graphql call. I tried all the known options. pom.xml

            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-graphql</artifactId>
        </dependency>
<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

class

@Controller

public class DemoGraphQLResolver {



  @QueryMapping(name = "phoneNumber")
  public List<Party> phoneNumber(@Argument String phoneNumber) {
    return phoneNumber;
  }
}

I have .graphqls file under src/main/resources/graphql.

[INFO] [, ] [main] org.springframework.graphql.execution.DefaultSchemaResourceGraphQlSourceBuilder - Loaded 1 resource(s) in the GraphQL schema. [INFO] [, ] [main] org.springframework.boot.autoconfigure.graphql.servlet.GraphQlWebMvcAutoConfiguration - GraphQL endpoint HTTP POST /graphql

above logs shows it loaded schema file and exposed endpoint but while requesting through postman i am getting 405 method not allowed

postman

POST http://localhost:8802/graphql

I am fairly new to graphql and any help on this is appreciated. Thanks


Solution

  • After going through all documentation and other resources. I was able to find the bug in latest spring upgrade for graphql.

    1. graphql schemas needs to be in src/main/resources/graphql/
    2. If there is an any API existing with GET method where it take single variable as path variable then default graphql request will be sent to that api and api throw 405 as response. This is some kind of bug we found after upgrading to spring-boot 3x. Only way to solve this issue is provide unique URI for graphql and providing that path in application.yml. in my case default /graphql endpoint changed to /query/graphql after updatin yml file as spring.graphql.path : /query/graphql