-
Notifications
You must be signed in to change notification settings - Fork 3
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
Improve fragment matching (resolveType) #58
Comments
It seems apollo has something called
|
Apollo seems to be moving away from fragment matcher:
|
This is the apollo way now: https://www.apollographql.com/docs/react/v3.0-beta/data/fragments/#defining-possibletypes-manually
I guess this means they always know '__typename`. Perhaps their old solution is a better fit for graphql-norm. |
This seems to be the old apollo way: export type FragmentMatcher = (
rootValue: any,
typeCondition: string,
context: any,
) => boolean; So some kind of callback that returns a boolean seems like the way to go... |
Currently the default
resolveType
function assumes that every object has a__typename
.The only time
resolveType
is called is when we need to determine if a certain fragment should be applied or not. Most of the time you have a single fragment but becuase of union types you can have multiple fragments on the same object. Consider this example:Here the first fragment should be applied if the
SchoolBook.__typename === "TextBook"
and the second fragment ifSchoolBook.__typename === "ColoringBook"
. In order to know this we run resolveType() and compare the __typename.You can run into problems with denormalize if you don't have
__typename
everywhere (even if you had it for normalize).Perhaps we can replace
resolveType
with something likeshouldApplyFragment
which by default returnstrue
so all fragments are always applied. This way the simple cases with a single fragment would work without having to add__typename
everywhere in the query.The text was updated successfully, but these errors were encountered: