-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 https://localhost:8802/graphql
I am fairly new to graphql and any help on this is appreciated. Thanks
3
2 Answers
Reset to default
0
By default, GraphQL queries should be sent as a POST request, not a GET request. When you try to access the /graphql
endpoint using a GET request, it’s likely to return a 405 error since the endpoint is configured to handle only POST requests.
In Postman, set HTTP method to POST. In the request body, provide your GraphQL query in JSON format for example:
{
"query": "{ phoneNumber(phoneNumber: "yourPhoneNumber") { /* fields you want to retrieve */ } }"
}
1
-
I am using POST method and getting this issue. Sorry i didn't mentioned method in my question
– AbhishekAug 1 at 11:12
0
After going through all documentation and other resources. I was able to find the bug in latest spring upgrade for graphql.
- graphql schemas needs to be in src/main/resources/graphql/
- 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
Not the answer you're looking for? Browse other questions tagged
or ask your own question.
or ask your own question.
Don't you need to annotate that controller method with something like
@PostMapping("graphql")
?Aug 1 at 7:47
And are you sure that Postman is set to use HTTP POST?
Aug 1 at 7:49
Jorn, Yes I am using POST request and I don't think i need @postmapping. since it should be autoconfigured from spring-boot-starter-graphql dependency
Aug 1 at 11:11
|