relay-compiler 13.x fails to compile queries on unions where members have identical field names of different types
- Dominant language
- Rust
- Stars
- 19k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
I encountered a regression when updating from relay-compiler@12.0.0 to relay-compiler@13.0.1. The compiler fails to compile heterogenous collections where members have identical field names of different types.
### Minimal Reproduction
https://codesandbox.io/s/pensive-wescoff-jrsh0
### Relevant Files
// schema.graphql
```graphql
type Bar {
id: ID!
title: String
viewCount: Int
}
type Baz {
id: ID!
title: String!
viewCount: Int!
}
union BarBaz = Bar | Baz
type Query {
foos: [BarBaz]
}
```
// main.js
```graphql
import { graphql } from "react-relay";
const barFragment = graphql`
fragment main_bar on Bar {
id
title
viewCount
}
`;
const bazFragment = graphql`
fragment main_baz on Baz {
id
title
viewCount
}
`;
const query = graphql`
query main_Query {
foos {
__typename
... on Bar {
id
title
viewCount
}
... on Baz {
id
title
viewCount
}
}
}
`;
```
### Error Output
```sh
querying files to compile...
[default] compiling...
[ERROR] ✖︎ Field 'title' is ambiguous because it references fields with different types: 'title' with type 'String' and 'title' with type 'String!'
main.js:7:9
6 │ id
7 │ title
│ ^^^^^
8 │ viewCount
ℹ︎ the other field
main.js:12:9
11 │ id
12 │ title
│ ^^^^^
13 │ viewCount
[ERROR] ✖︎ Field 'viewCount' is ambiguous because it references fields with different types: 'viewCount' with type 'Int' and 'viewCount' with type 'Int!'
main.js:8:9
7 │ title
8 │ viewCount
│ ^^^^^^^^^
9 │ }
ℹ︎ the other field
main.js:13:9
12 │ title
13 │ viewCount
│ ^^^^^^^^^
14 │ }
[ERROR] Compilation failed.
[ERROR] Failed to build:
- Validation errors:
- Field 'title' is ambiguous because it references fields with different types: 'title' with type 'String' and 'title' with type 'String!':main.js:88:93
[related 1] the other field:main.js:158:163
- Field 'viewCount' is ambiguous because it references fields with different types: 'viewCount' with type 'Int' and 'viewCount' with type 'Int!':main.js:102:111
[related 1] the other field:main.js:172:181
```
### Expectation
The query should compile.
Contributor guide
Assessment
This issue has not been assessed yet.