-
Notifications
You must be signed in to change notification settings - Fork 117
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
feat: Add support for better fragment type resolution #199
feat: Add support for better fragment type resolution #199
Conversation
2ff2fb5
to
b759691
Compare
0ac013c
to
d147401
Compare
d147401
to
a3f8930
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the PR!
One question: is there an advantage to using a possibleTypeOf
Map instead of a possibleTypes
Map? Apollo uses the latter, and it feels more intuitive to define possible types for an interface rather than possible interfaces for a type.
@@ -15,6 +15,7 @@ Map<String, dynamic> operationRootData<TData, TVars>( | |||
request.operation.operationName!, | |||
(request.vars as dynamic).toJson(), | |||
typePolicies, | |||
{}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should include the possible types as an argument to operationRootData
and pass them in here.
I don't see any immediate benefits one way or another. Apollo using the latter is a good argument for going in that direction. I'll rewrite! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This PR adds improved support for fragment resolution by introducing a new map to lookup type relationship
Take the document:
and the schema
the current implementation will fail to realize which fragment spreads apply to a given type. E.g. that
FUser
andFAuthor
should apply to theAuthor
type. This leads to partial results on fragments and wrong results on inline fragments. By adding some introspection in the shape of thepossibleTypeOf
lookup map, which maps object types to possible interfaces and unions, we can resolve this.If the map is omitted, or if the
__typename
is omitted, this solution will not expand any fragments. This is sound. The current approach expands all fragment spreads and only expands on exact matches for inline fragments, both of which are wrong.