dotansimha / dotansimha/graphql-code-generator
mergeFragmentTypes should merge
- Dominant language
- TypeScript
- Stars
- 11.3k
- Forks
- 1.4k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 23
Description
### Which packages are impacted by your issue?
@graphql-codegen/typescript-operations
### Describe the bug
The `mergeFragmentTypes` only removes fragments using the string equality. It does not remove fragments when they can extend each other.
### Your Example Website or App
https://stackblitz.com/edit/github-uxy2hb?file=types.ts
### Steps to Reproduce the Bug or Issue
1. generate the types
2. the `user` query generated type is `{ user: { id: string, username: string, email: string } | { id?: string | null, username: string, email: string } }` while it can be `{ id?: string | null, username: string, email: string } }` because the latter type in the union extends the former.
3. The same is true for the removed query. (we cannot simply use the interface type here we should remove the union members that extend each other)
### Expected behavior
I expect the `mergeFragmentTypes` option to be smarter and remove union types that extend each other.
### Platform
- NodeJS: 20
- `graphql` version: 16.6.0
- `@graphql-codegen/*` version(s): 4.0.1
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.