Closed vincentisambart closed 9 months ago
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.
@vincentisambart - this has been fixed and will go out in the next release.
@calvincestari Thanks a lot!
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.