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

Allow down casting query trail interface and union types #63

Merged
merged 1 commit into from
Oct 5, 2019

Conversation

davidpdrsn
Copy link
Owner

@davidpdrsn davidpdrsn commented Sep 10, 2019

This is part of fixing
davidpdrsn/juniper-eager-loading#15.

In order to perform eager loading on a Vec<User> you need to know
which associations are being queried. The QueryTrail<User, _> type has
that information.

However, this doesn't work for interfaces since if you have an interface
called for example Entity you will not get a QueryTrail<User, _> but
instead a QueryTrail<Entity, _>. That doesn't work to eager load
users, which means you cannot eager at all. This is because Entity is
an enum with a variant for each type that implements that interface.

With this change we also generate implementations of Into for
QueryTrail<Entity, _> into each type that implements it. That allows
you get a QueryTrail<User, _> to do eager loading with.


TODO:

  • Test that actually eager loads association and uses the associations QueryTrail
  • Update docs

@davidpdrsn davidpdrsn self-assigned this Sep 10, 2019
@davidpdrsn davidpdrsn force-pushed the allow-converting-between-query-trail-types branch 2 times, most recently from dda0318 to 920c0c0 Compare September 10, 2019 21:02
@davidpdrsn davidpdrsn force-pushed the allow-converting-between-query-trail-types branch from 920c0c0 to ceaa301 Compare October 5, 2019 09:44
This is part of fixing
davidpdrsn/juniper-eager-loading#15.

In order to perform eager loading on a `Vec<User>` you need to know
which associations are being queried. The `QueryTrail<User, _>` type has
that information.

However, this doesn't work for interfaces since if you have an interface
called for example `Entity` you will not get a `QueryTrail<User, _>` but
instead a `QueryTrail<Entity, _>`. That doesn't work to eager load
users, which means you cannot eager at all. This is because `Entity` is
an enum with a variant for each type that implements that interface.

With this change we also generate implementations of `Into` for
`QueryTrail<Entity, _>` into each type that implements it. That allows
you get a `QueryTrail<User, _>` to do eager loading with.
@davidpdrsn davidpdrsn force-pushed the allow-converting-between-query-trail-types branch from ceaa301 to 1e90905 Compare October 5, 2019 09:45
@davidpdrsn davidpdrsn marked this pull request as ready for review October 5, 2019 09:45
@davidpdrsn davidpdrsn merged commit 1e90905 into master Oct 5, 2019
@davidpdrsn davidpdrsn deleted the allow-converting-between-query-trail-types branch October 5, 2019 10:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant