graphql-codegen-plugin-typescript-swr
graphql-codegen-plugin-typescript-swr copied to clipboard
Conditional Fetching
-
I'm submitting a ... [ ] bug report [ ] feature request [ ] question about the decisions made in the repository [ X] question about how to use this project
-
Summary
-
how to use Conditional Fetching with the generated query?
-
Other information (e.g. detailed explanation, stack traces, related issues, suggestions how to fix, links for us to have context, eg. StackOverflow, personal fork, etc.)
-
https://swr.vercel.app/docs/conditional-fetching
Interested in how people are going about this too!
It's the same as a normal SWR hook:
const { data, mutate } = getSdkWithHooks().useMyQuery(isTrue ? 'QueryName' : null);
This is when the key is provided by the user. Is there any alternative when the key is autogenerated? I think it's not possible at the moment. If I can propose some solutions:
- Add a
skip
config so that the function that generates the key returns null in case skip is true - Implement #158 and this would be solved as well
While waiting for this feature to be implemented, I create a fork (published on npm) that let you conditional fetch (and other things). https://github.com/ramiel/graphql-codegen-plugin-typescript-swr
I also made a PR with a POC