apollographql / apollographql/apollo-tooling
Generated types include unused unions.
- Dominant language
- TypeScript
- Stars
- 3k
- Forks
- 460
- PR merge metrics
- No merged PRs in 30d
Description
Not sure if it is correct behaviour to include all possible union types, even the unused ones, to a generated type file.
When codegen is run for this query:
```ts
export const NEW_SKILL_CARD_SEARCH_QUERY = gql`
query SearchQuery {
search(query: "*") {
hits {
... on CVHit {
__typename
id
}
}
}
}
`
```
It gives out typescript like this:
```ts
export interface SearchQuery_search_hits_CustomerHit {
__typename: "CustomerHit" | "ProjectHit" | "SuggestionHit";
}
export interface SearchQuery_search_hits_CVHit {
__typename: "CVHit";
id: string | null;
}
export type SearchQuery_search_hits = SearchQuery_search_hits_CustomerHit | SearchQuery_search_hits_CVHit;
export interface SearchQuery_search {
__typename: "SearchResult";
hits: (SearchQuery_search_hits | null)[] | null;
}
```
My question is, why are types `"CustomerHit" | "ProjectHit" | "SuggestionHit"` included in generated types, even thou only `"CVHit"` is used in the search query?
Now I will have to trick typescript to comply like this: `search.hits as SearchQuery_search_hits_CVHit[]`
Contributor guide
Research direction
Reproduce the issue by running codegen for the provided SearchQuery and compare the generated SearchQuery_search_hits_CustomerHit and SearchQuery_search_hits definitions with the inline fragment selecting CVHit. Trace the code-generation entry point responsible for unions and determine whether the unused union members are intentional; done means the behavior is corrected or clearly documented with an explanation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100