question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG][Federation Gateway]: GraphQLError when query union types containing field with same name but different type

See original GitHub issue

Taking this schema example :

Screenshot 2020-02-26 at 13 32 11

With this resolver for the Body union type:

Screenshot 2020-02-26 at 13 33 24

With this query:

Screenshot 2020-02-26 at 12 14 38I am getting the error "GraphQLError: Cannot query field \"url\" on type \"TextAttributes\"" even if we have inline fragments in the query ( ...on Text {}, ...on Image {} )

Obviously, that the issue here comes from attributes field name which is defined for both types - Text and Image and seems that for some reason it looks for Image.attributes.url in Text type as well.

My question is : is that GraphQL Apollo Server union type limitation ( when union types contains same field name but with different type ) or I’m missing something and some piece of schema def is wrong ?

NOTE: if I rename the attributes field name to be unique foe each union type, it works fine.

UPDATE : This issue is produced only when using Apollo Federation , the query is executed against the Apollo’s Gateway which expose the data from different underlying data services. If we send the same query agains the particular underlying service - it works fine without any errors.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:15
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
gsgallowaycommented, Apr 13, 2020

Seems to have been patched in @apollo/gateway: "0.14.0"

1reaction
nialloc9commented, Feb 28, 2020

Any update on this? Also causing a problem here.

This is 100% an issue with apollo gateway. If you run the query on just your underlying data service it works fine with the unions. However, if you run it using federation and against the gateway it fails. It seems that the federated global graph is the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unions and interfaces - Apollo GraphQL Docs
Unions and interfaces are abstract GraphQL types that enable a schema field to return one of multiple object types. Union type.
Read more >
Using same field names in different types within union
Using Union; Using a String with additional type information. All not very nice but working. I put a simple example project with all...
Read more >
Union types in GraphQL - Dev - Discuss Dgraph
Motivation Support union types in GraphQL as specified in the GraphQL spec. ... Unions can be queried only as a field of some...
Read more >
GraphQL Error Handling with Union Types - Episode #30
The GraphQL Spec briefly discusses error handling in its simplest form for both requests, and field, but if you're used to working with ......
Read more >
Union types - Ariadne GraphQL
Every type in GraphQL has a special __typename field that is resolved to a string containing the type's name. Including this field in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found