Description
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:
query GetBooks {
schoolBooks {
title
... on TextBook {
classes {
name
}
}
... on ColoringBook {
colors {
name
}
}
}
}
Here the first fragment should be applied if the SchoolBook.__typename === "TextBook"
and the second fragment if SchoolBook.__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 like shouldApplyFragment
which by default returns true
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.