dotansimha / dotansimha/graphql-code-generator
Can the `client` param not be hardcoded? Or be replaced when generating?
- 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.**
I'm coming late into a codebase that uses graphql-code-generator + react-query. It works okay, but one of the pain points I've heard about is that all the queries have to explicitly have a graphqlclient instance passed into them. [Looking at the source code](https://github.com/dotansimha/graphql-code-generator/blob/5c7592b4dde8a8035c33eeeb89a1682cdf2a34fa/packages/plugins/typescript/react-query/src/fetcher-graphql-request.ts#L82), it looks like there's no way to override this.
**Describe the solution you'd like**
Ideally, we'd be able to set a client provider within something like React Context, and the hooks would use that automatically. This would not only avoid repetition in importing the client, but the big problem we're having now is that _because_ we explicitly pass the client in, it makes this hard (or harder) to mock for tests. Ideally we would be able to set any client provider for context and have components use that GraphQLClient povider.
**Describe alternatives you've considered**
By looking at the code, there are no alternatives. The generated code seems to leave no room for removing this parameter, or inheriting from context (or some transform / wrapper like that?)
**Additional context**
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.