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.

Querying same field w/ and w/o attributes for different union types results in error

See original GitHub issue

Query:

{
  curatedList {
     ...on Program {
        title(lang: "fi")
     }

     ...on Article {
        title
     }
  }
}

Error:

Fields title conflict because they have differing arguments.

Should it really work like that, or is this a bug?

Article and Program are both members of union type Content

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:7
  • Comments:23 (8 by maintainers)

github_iconTop GitHub Comments

22reactions
jbmikkcommented, Jan 18, 2021

This is so bad, I have several TS interfaces and I expect my results to match those interfaces, if I start aliasing the unions then they won’t match and I’m going to have to convert the results to match the TS interfaces.

I’m going to use just a plain JSONResolver for the conflicting fields. Graphql should support unions for scalars, and if that goes against the spec, then the spec is probably wrong and should be fixed. There should be at least a way to relax this or provide a solution that does not imply aliasing or having to interpret the results after in any way.

Union types are ambiguous by definition, you either support them or you don’t.

11reactions
leebyroncommented, Jul 14, 2015

I think we could probably improve this if two fields are known to never “merge”. In this case, the two types are Object types and in no condition would both “title” fields be queried for the same object.

We should be a bit smarter about this (likely common) case

Read more comments on GitHub >

github_iconTop Results From Across the Web

SQL UNION overview, usage and examples
This article provides overview of the SQL UNION operator, along with examples and explore some common questions like the differences between ...
Read more >
sql - UNION ALL two SELECTs with different column types
If you want to use union all columns in every query need to have the same type. C3 must be converteted to varchar...
Read more >
Handling GraphQL errors like a champ with unions and ...
Error handling can be frustrating in GraphQL. This post shows you how to use unions and interfaces to handle errors in a more...
Read more >
Customizing the behavior of cached fields - Apollo GraphQL
You can customize how a particular field in your Apollo Client cache is read and written. To do so, you define a field...
Read more >
Use a union query to combine multiple queries into a single ...
Get a combined view of multiple select queries with a union query. ... compatible data types with fields in the same position 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