New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GraphQL Endpoints shadowed by RequestMappings #404
Comments
Side note: 404 is the perfect issue number for this issue. ;) |
Indeed, the GraphQL endpoint is mapped as a In the meantime, one option is to create this catch-all handler as a @Bean
public RouterFunction<?> routerFunction() {
return RouterFunctions.route()
.route(RequestPredicates.all(), request -> ServerResponse.notFound().build())
.build();
} Also, if you didn't have it all, you should still get a 404 by default. |
In my opinion, the Spring Boot auto-configuration is consistent with the Spring MVC opinion here. We're merely using the functional endpoints as a way to contribute controller handlers; this is probably the best choice when it comes to programmatic contributions like this. Any |
@rstoyanchev Thanks for the suggested It works, but I have to explicitly ignore @Bean
public RouterFunction<?> routerFunction() {
return route()
.route(
request -> !request.path().startsWith("/graphql") &&
!request.path().startsWith("/graphiql"),
request -> EntityResponse
.fromObject(
new RestError(
HttpStatus.NOT_FOUND,
"There is no resource for path " + request.uri()
))
.status(404)
.build()
)
.build();
} Regarding the following part of your comment:
You are right, that I get a 404 if I don't have a catch-all However this is still not an ideal solution in our case. Our WebApp consists of a UI which is implemented using Apache Wicket and some REST-Endpoints that are implemented with Spring Web MVC. A user that get's a 404 inside the wicket application should get a nice Error-HTML-Page. A WebService API user should get a JSON Response instead. Currently we are able to provide nice Error Pages via
If we don't handle the 404 in the WebService part, then all |
It worked in my case, but it looks like the order is not deterministic. We've discussed this and created related issues spring-projects/spring-framework#28595 and spring-projects/spring-boot#31314 to ensure @Bean
@Order(1)
public RouterFunction<?> routerFunction() {
// ...
} Aside from that, |
Closing for now in favor of the two related issues. |
I want to integrate GraphQL into an application that already provides a rest api.
The application contains a
RequestMapping
that is used as fallback, if noController
method exists for handling the request:A corresponding
ExceptionHandler
exists, that converts the ResourceNotFoundException into a 404 JSON ResponseEntity.Now having this
RequestMapping
in place, I get a 404 if I call any of the GraphQL Endpoints.The text was updated successfully, but these errors were encountered: