[compiler] relay compiler does not generate separate type for union members
- Dominant language
- Rust
- Stars
- 19k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
Hello
I remember old relay compiler could generate separate type for each union member and then use generated types in union
But it is not possible anymore
For example for mutation like this
```
mutation updateCompany() {
__typename
... on Company {
...
}
... on Errors {
...
}
}
# this is how schema looks
union UpdateCompanyPayloadUnion = Company | Errors
updateCompany(): UpdateCompanyPayloadUnion
```
This is what generated now. Generated type does not have Company and Errors types
```
type Mutation$data = {
readonly updateCompany: {
readonly __typename: "Company";
readonly id: string;
...
} | {
readonly __typename: "Errors";
...
} | {
// This will never be '%other', but we need some
// value in case none of the concrete values match.
readonly __typename: "%other";
} | null;
};
```
Is it possible to make relay-compiler do this instead today?
```
type Company = {
readonly __typename: "Company";
readonly id: string;
...
}
type Errors = {
readonly __typename: "Errors";
...
}
type Mutation$data = {
readonly updateCompany: Company | Errors | {
// This will never be '%other', but we need some
// value in case none of the concrete values match.
readonly __typename: "%other";
} | null;
};
```
Contributor guide
Assessment
This issue has not been assessed yet.