facebook / facebook/relay

[compiler] relay compiler does not generate separate type for union members

Open
#4,186 0 comments 3 reactions 0 assignees View on GitHub
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.