dotansimha / dotansimha/graphql-code-generator
Explicit nested fragment usage
- 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.
Currently, using fragments depends on coupling components together using strings (their fragment names) and not much else. The fragment names are in a global namespace, and they're included wherever used. There's few ways to ensure that the correct name is used, there's few ways to ensure the fragments are used in the appropriate place, and it's just generally easy to make mistakes.
### Describe the solution you'd like
Require fragment data be passed in explicitly for each usage. Components have to export their fragment, and the graphql function would need to take the fragments as an argument.
This would unlock more static analysis checks, and put imports of components alongside their fragment, making it easy to remove a fragment's usage when the component is dropped -- and providing a way to statically analyze that this has happened.
(This should probably at least start as an option, not require by default. Does seem like a best practice to require by default in future, though.)
### Describe alternatives you've considered
gql.tada has a nice version of this, see here: https://gql-tada.0no.co/guides/fragment-colocation#nested-fragment-composition
### Is your feature request related to a problem? Please describe.
FYI this question is duplicated.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.