`relay-compiler` generates invalid Typescript for `@raw_response_type` + combination of conditional and non-conditional fragments
- Dominant language
- Rust
- Stars
- 19k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
Given the code below:
```ts
export const query = graphql`
query AppQuery($showEmail: Boolean!) @raw_response_type {
...AppFragment
...AppConditionalFragment
}
`;
export const fragment = graphql`
fragment AppFragment on Query {
account {
name
}
}
`;
export const conditionalFragment = graphql`
fragment AppConditionalFragment on Query {
account @include(if: $showEmail) {
email
}
}
`;
```
Relay compiler generates the following types (notice the `account` field is listed twice):
```ts
export type AppQuery$rawResponse = {
readonly account: {
readonly id: string;
readonly name: string;
} | null | undefined;
readonly account: {
readonly email: string;
} | null | undefined;
};
```
Which typescript interprets by using the first declaration of a given field and ignoring all others, leading to errors like:
This very reproduction can be found at https://github.com/vhfmag/relay-ts-typegen-issue-repro
Instead, relay compiler should generate something like:
```ts
export type AppQuery$rawResponse = {
readonly account: {
readonly id: string;
readonly name: string;
readonly email?: string | null | undefined;
} | null | undefined;
};
```
Contributor guide
Research direction
Start with the linked relay-ts-typegen-issue-repro and inspect the generated AppQuery$rawResponse type for the duplicate account fields. Trace the relay-compiler path that combines conditional and non-conditional fragment selections under @raw_response_type, then add a regression test showing one merged account field with email optional and verify the generated TypeScript.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust, typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100