Skip to content
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

Create optimized RequestPredicate for GraphQL endpoints #906

Closed
bclozel opened this issue Feb 12, 2024 · 4 comments
Closed

Create optimized RequestPredicate for GraphQL endpoints #906

bclozel opened this issue Feb 12, 2024 · 4 comments
Assignees
Labels
in: web Issues related to web handling type: enhancement A general enhancement
Milestone

Comments

@bclozel
Copy link
Member

bclozel commented Feb 12, 2024

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.

@bclozel bclozel added type: enhancement A general enhancement in: web Issues related to web handling labels Feb 12, 2024
@bclozel bclozel added this to the 1.3 Backlog milestone Feb 12, 2024
@bclozel bclozel self-assigned this Feb 12, 2024
@bclozel bclozel modified the milestones: 1.3 Backlog, 1.3.0-M1 Feb 17, 2024
bclozel added a commit that referenced this issue Jun 1, 2024
Prior to this commit, we introduced in gh-906 custom `RequestPredicates`
for faster and more efficient matching. These custom WebFlux and MVC
predicates did not set the matching `PathPattern` as a request attribute
for positive matches. This value is used by observability conventions
for metrics and traces KeyValues; as a result, observation metadata is
missing the "uri" metadata and is using the "UNKNOWN" value instead.

This commit adds the missing request attribute in our custom request
predicates.

Fixes gh-987
@fdulger
Copy link

fdulger commented Sep 20, 2024

@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
Copy link
Member Author

bclozel commented Sep 20, 2024

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

@bclozel
Copy link
Member Author

bclozel commented Sep 20, 2024

@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
Copy link

fdulger commented Sep 23, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues related to web handling type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants