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

Review GraphQL Query auto-configurations #34974

Closed
rstoyanchev opened this issue Apr 13, 2023 · 9 comments
Closed

Review GraphQL Query auto-configurations #34974

rstoyanchev opened this issue Apr 13, 2023 · 9 comments
Assignees
Labels
type: task A general task
Milestone

Comments

@rstoyanchev
Copy link
Contributor

The four auto config classes in autoconfigure/graphql/data -- Querydsl, Query by Example, reactive and non-reactive, all detect repositories auto-register them for GraphQL queries.

It's possible for more than of these to be able to auto-register for a query. For example see spring-projects/spring-graphql#661 where same repository is both Querydsl and QBE. If that happens the first registration wins, which as the four configuration classes can load in any order, it means that sometimes you may get Querydsl once, and QBE the next time.

It would be good to load these in a stable order so at least you get a consistent result. We've discussed this on the GraphQL team with @mp911de and @bclozel, and decided we could have Querydsl run ahread of QBE. Perhaps also reactive ahead of non-reactive.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 13, 2023
@wilkinsona
Copy link
Member

which as the four configuration classes can load in any order, it means that sometimes you may get Querydsl once, and QBE the next time

This shouldn't be the case. In the absence of any before and after constraints, auto-configurations are ordered alphabetically. This should result in the following ordering:

  1. GraphQlQueryByExampleAutoConfiguration
  2. GraphQlQuerydslAutoConfiguration
  3. GraphQlReactiveQueryByExampleAutoConfiguration
  4. GraphQlReactiveQuerydslAutoConfiguration

This isn't the desired ordering, but it should be consistent. We can of course modify the ordering but it would be a breaking change so I'd welcome your thoughts on the timing. Perhaps it should only be done in a new minor rather than in a maintenance release?

It sounds like the desired ordering is the following:

  1. GraphQlReactiveQuerydslAutoConfiguration
  2. GraphQlQuerydslAutoConfiguration
  3. GraphQlReactiveQueryByExampleAutoConfiguration
  4. GraphQlQueryByExampleAutoConfiguration

@wilkinsona wilkinsona added the status: waiting-for-internal-feedback An issue that needs input from a member or another Spring Team label Apr 13, 2023
@rstoyanchev
Copy link
Contributor Author

This is good to know that there is a consistent order at least. The main goal was to have consistency, but otherwise probably no ideal order. I think it would be fine to close this issue unless @mp911de disagrees.

It's probably more important how one would customize the order if needed, but at this point it's not a real issue, so only consider it if there is a reasonably straight forward change to make.

@wilkinsona
Copy link
Member

wilkinsona commented Apr 14, 2023

Looking more closely at the code, I'm not sure that the ordering of the configuration classes matters here. Each configuration class defines a GraphQlSourceBuilderCustomizer bean. As far as I can tell, it's the ordering of these customisers that matters. The auto-configuration for GraphQlSource applies these customisers in order, but they don't express an order so they'll all have lowest precedence. As such, I think I was mistaken earlier and the ordering that matters isn't necessarily going to be consistent. It depends on the behavior of ObjectProvider.orderedStream() for unordered entries.

@rstoyanchev
Copy link
Contributor Author

I see what you mean. Yes, it comes down to the order of GraphQlSourceBuilderCustomizer beans. Maybe we can leave this as is for the time being until we see an actual use case.

There might be a couple of small things to review and possibly correct. I think the 4 auto-configuration classes are each meant to create a customizer for one category of repositories. The reactive variants comply with that and detect only reactive repositories for either Querydsl or QBE. The non-reactive ones detect both reactive and non-reactive, but should probably detect non-reactive ones only. Also, GraphQlQuerydslSourceBuilderCustomizer should not have Querydsl in its name since it's not only for Querydsl. Perhaps DataGraphQlSourceBuilderCustomizer (or Query, AutoRegistration), or something similar.

@philwebb philwebb changed the title Fixed order for GraphQL Querydsl vs Query By Example auto configuration Fixed order for GraphQL Querydsl vs Query By Example auto-configuration and polish naming Jun 7, 2023
@philwebb philwebb added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged status: waiting-for-internal-feedback An issue that needs input from a member or another Spring Team labels Jun 7, 2023
@philwebb philwebb added this to the 3.2.x milestone Jun 7, 2023
@bclozel bclozel self-assigned this Sep 8, 2023
@bclozel bclozel added type: task A general task and removed type: enhancement A general enhancement labels Sep 8, 2023
@bclozel bclozel changed the title Fixed order for GraphQL Querydsl vs Query By Example auto-configuration and polish naming Review GraphQL Query auto-configurations Sep 8, 2023
@bclozel
Copy link
Member

bclozel commented Sep 8, 2023

I see what you mean. Yes, it comes down to the order of GraphQlSourceBuilderCustomizer beans. Maybe we can leave this as is for the time being until we see an actual use case.

I've left the order as is for now, since we didn't get any feedback on that so far. I've turned this issue into a task to address Rossen's feedback on auto-configurations.

@bclozel bclozel modified the milestones: 3.2.x, 3.2.0-M3 Sep 8, 2023
@bclozel bclozel closed this as completed in 1694051 Sep 8, 2023
@wilkinsona
Copy link
Member

These changes appear to be the cause of some build failures when Query DSL isn't on the classpath. I think we need to update the conditions on GraphQlQuerydslAutoConfiguration to back off in Query DSL's absence.

@wilkinsona wilkinsona reopened this Sep 11, 2023
@wilkinsona wilkinsona self-assigned this Sep 11, 2023
bclozel added a commit that referenced this issue Sep 11, 2023
This commit fixes build issues, as the recent changes surfaced an
existing problem: QueryDsl auto-configurations were not guarded by
classpath conditions for QueryDsl Core.

See gh-34974
@bclozel
Copy link
Member

bclozel commented Sep 11, 2023

Sorry @wilkinsona I've just noticed you've reopened this issue. I've just pushed changes in c951c4c to fix the missing classpath condition checks. I'm not sure how those were not surfaced before. There was probably some indirection before that was preventing the relevant classes to be loaded in other tests. Still those conditions were missing in the first place and we shouldn't contribute those customizers when QueryDsl is not on the classpath.

I'll close this issue when the build is green.

@bclozel
Copy link
Member

bclozel commented Sep 11, 2023

We're good now, see this build.
Closing with c951c4c.

@wilkinsona
Copy link
Member

No worries, Brian. Thanks for the changes. I'd written a couple of tests so I've just pushed those in 14a59a3. I think they're worth having as the failures were from tests in a different module and I think it's good to have coverage in the same module.

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

No branches or pull requests

5 participants