dotansimha / dotansimha/graphql-code-generator
Avoid extra __typename when using inlineFragmentTypes: combine
- Dominant language
- TypeScript
- Stars
- 11.3k
- Forks
- 1.4k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 23
Description
**Is your feature request related to a problem? Please describe.**
When using `inlineFragmentTypes: 'combine'`, query types gets a redundant `__typename` definition for each possible type. Since every fragment will get its own type, which also has the same `__typename` in it, adding another `__typename` by itself becomes redundant. By avoiding that, we could make the generated code more readable(_not really important for most people_), reduce the file sizes(_not crucial either_), and more importantly, have more readable IDE-provided type information.
Document:
```graphql
fragment UserSummaryFragment on User {
id
name
}
query getUsers {
users {
...UserSummaryFragment
}
}
```
Generated code:
```ts
export type UserSummaryFragment = {
__typename?: 'User';
id: string;
name: string;
email: string;
avatar: string;
};
export type GetUsersQueryVariables = Types.Exact<{ [key: string]: never }>;
export type GetUsersQuery = {
users: Array<{ __typename?: 'User' } & UserSummaryFragment>;
};
```
When hovering over the type:

This gets even worse when using it with `preResolveTypes: false`:

**Describe the solution you'd like**
Generated code:
```ts
# ...
export type GetUsersQuery = { users: Array };
```
When hovering over the type:

Has the same generated code(_query type part_) and IDE behavior when using `preResolveTypes: false`.
Of course, it would still need to generate `__typename` if there are no fragments.
**Describe alternatives you've considered**
To live with it 😭
**Additional context**
...
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.