spring-projects / spring-graphql

Spring Integration for GraphQL
https://spring.io/projects/spring-graphql
Apache License 2.0
1.53k stars 305 forks source link

Create optimized RequestPredicate for GraphQL endpoints #906

Closed bclozel closed 9 months ago

bclozel commented 9 months ago

Right now, the Spring Boot auto-configuration composes several RequestPredicate instances to handle GraphQL requests. Composing there can incur some overhead and no practical advantage in our case. Spring for GraphQL should instead provide custom RequestPredicate implementations that are optimized for optimal performance.

They should be then leveraged in the Spring Boot auto-configuration.

fdulger commented 1 month ago

@bclozel Is it possible to customize this behavior? I see that GraphQlRequestPredicates is enforcing "application/json" or "application/graphl" content types on requests, which is fine as this is indicated as a must in the graphql spec. In our case, we're migrating from another graphql library to spring now, and we realize that out previous implementation was also allowing requests which do not contain any content-type header. In order to keep our application behaving the same, we would like to be able to use a custom RequestPredicate. I couldn't find any instructions on how to do so.

bclozel commented 1 month ago

@fdulger you can implement a custom request predicate, similar to the ones in GraphQlRequestPredicates and use it in your standalone setup.

bclozel commented 1 month ago

@fdulger Another idea: you could configure a Servlet Filter that wraps the request and manually sets a Content-Type if it is empty and path targets the graphql endpoint. You could then even track the lagging clients at this stage. This is probably less complex and would not require undoing Spring Boot auto-configuration.

fdulger commented 1 month ago

Thanks a lot for the suggestions! Servlet filter indeed does the work.