dotansimha / dotansimha/graphql-code-generator-community

[react-query] always allow getKey with no variables

Open
#18 6 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
137
Forks
195
Avg merge
6h 20m
Merged PRs (30d)
16

Description

**Is your feature request related to a problem? Please describe.**
React-query lets us [invalidate all queries](https://tanstack.com/query/v4/docs/guides/query-invalidation) for a given operation by omitting the variables. In this case, we would need to call `useXxx.getKey()` with no variables. However at the moment variables are marked as required in `getKey`'s signature if the operation has required variables. This is true for the signature of `fetcher`, but not `getKey`.

**Describe the solution you'd like**
I would like `getKey` to have optional variables no matter the operation.

**Describe alternatives you've considered**
The only alternative at the moment is to call `getKey` with fake variables and then take the first item of the returned array.

**Additional context**
I think implementation would simply be to replace `hasRequiredVariables` by `false` at https://github.com/dotansimha/graphql-code-generator-community/blob/47631df085f7e8cd42d5f10bca6977a69514e18d/packages/plugins/typescript/react-query/src/visitor.ts#L184 and https://github.com/dotansimha/graphql-code-generator-community/blob/47631df085f7e8cd42d5f10bca6977a69514e18d/packages/plugins/typescript/react-query/src/visitor.ts#L200

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.