You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On a union, when you have an inline fragment just getting __typename and no real field, the asMyObject property does not return nil when the type is not MyObject.
Looking at the difference of behavior, if the inline fragment's selection set is empty (other that __typename), the AsMyObject struct implements ApolloAPI.CompositeInlineFragment, but does not if the selection set has other fields in it. That changes the version of _asInlineFragment called (in the empty case func _asInlineFragment<T: CompositeInlineFragment>() -> T? gets called, in the non empty case func _asInlineFragment<T: SelectionSet>() -> T? gets called).
It looks like to me that an empty inline fragment should not implement CompositeInlineFragment, especially at is has no __mergedSources, meaning that _asInlineFragment will never return nil, but I'm not sure of the implications of this.
The text was updated successfully, but these errors were encountered:
Hi @vincentisambart, thanks for raising this issue. It seems funky to have two different behaviours so we'll certainly take a look into it and try get a reproduction case.
@vincentisambart - I debugged this today and I think you're correct that ApolloAPI.CompositeInlineFragment is the incorrect protocol to be conforming to. FWIW, the reason _asInlineFragment is giving the incorrect result is because the generated model incorrectly defines an empty __mergedSources list which is used to match against the returned types.
Going back a few releases it looks like this bug has existed for a while, but I've got a reproduction case now and we'll get it resolved.
Summary
On a union, when you have an inline fragment just getting
__typename
and no real field, theasMyObject
property does not returnnil
when the type is notMyObject
.Version
1.8.0
Steps to reproduce the behavior
As an example, take this GraphQL schema:
And this query:
If
main.thing
is aMyError
, I would expectmain.thing.asMyObject
to returnnil
but it does not.Note that if you add a real field to the inline fragment's selection set like the example below, you will correctly get
nil
ifmain.thing
is aMyError
Logs
No response
Anything else?
Looking at the difference of behavior, if the inline fragment's selection set is empty (other that
__typename
), theAsMyObject
struct implementsApolloAPI.CompositeInlineFragment
, but does not if the selection set has other fields in it. That changes the version of_asInlineFragment
called (in the empty casefunc _asInlineFragment<T: CompositeInlineFragment>() -> T?
gets called, in the non empty casefunc _asInlineFragment<T: SelectionSet>() -> T?
gets called).It looks like to me that an empty inline fragment should not implement
CompositeInlineFragment
, especially at is has no__mergedSources
, meaning that_asInlineFragment
will never returnnil
, but I'm not sure of the implications of this.The text was updated successfully, but these errors were encountered: