This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Abstract projection overfetching when using intermediary projections #4995
Labels
You can continue the conversation there. Go to discussion →
Is there an existing issue for this?
Describe the bug
#3650 implements what was called "abstraction projections", which as far as I'm concerned, enables your GraphQL schema to follow your EF Core model if you're taking advantage of inheritance in EF Core.
So, given an app set up like the following:
Program.cs
:Now, if a query like the following is executed against this GraphQL server:
The projection middleware now understands the inheritance side of things and thus generates the right projection expression, which is reflected in the resulting SQL that EF Core ultimately generates:
However, now imagine you have some sort of an "intermediary projection", here's the same setup above, with some additional DTO classes:
Now, if you execute the same GraphQL query mentioned above against this GraphQL server, the resulting SQL will be very different:
Notice how
Title
is being retrieved even though it was not requested in the GraphQL query. Actually, right now, ALL the columns are fetched from the data and the projection, therefore, is more or less useless.Now, I think it's worth mentioning that this is fundamentally related to #2373, as both problems actually share the same underlying issue. That being the fact that EF doesn't really recognize that it should treat instances of
LessonDto
andLessonDto
as equivalent when used in a projection expression on their own.To get a better understanding of this, take this as an example:
The generated SQL will be:
As expected.
But if you do:
Now we get quite a different looking SQL:
Clearly, EF Core is fetching everything once again, and the fundamental reason for this is that EF Core doesn't understand that
l
in a.Select(l => ...)
wherel
is of typeLessonDto
should be considered equivalent tol
in.Select(l => ...)
wherel
isLesson
, when the parameter is used on its own as an operand in an operation like this, or the case of #2373, in a null-checking operation, which was the root of the overfetching problem there as well.I'd like us to perhaps discuss the various possible solutions to problems of this sort. If HC itself can't do much about this, maybe we can prepare a proposal for a feature for EF Core that would solve all the problems of this nature, problems that arise when using intermediary projections.
In other words, maybe solutions like #4985 are, in a sense, treating the symptoms, rather than the actual root cause of the problem.
Let me know your thoughts.
Steps to reproduce
Described above.
Relevant log output
No response
Additional Context?
No response
Product
Hot Chocolate
Version
12.8.0
The text was updated successfully, but these errors were encountered: