Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditional Fetching #157

Open
raymclee opened this issue Jun 26, 2021 · 4 comments
Open

Conditional Fetching #157

raymclee opened this issue Jun 26, 2021 · 4 comments

Comments

@raymclee
Copy link

  • 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

@fishactual
Copy link

Interested in how people are going about this too!

@adarnon
Copy link

adarnon commented Feb 16, 2022

It's the same as a normal SWR hook:

const { data, mutate } = getSdkWithHooks().useMyQuery(isTrue ? 'QueryName' : null);

@ramiel
Copy link

ramiel commented Feb 17, 2022

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:

@ramiel
Copy link

ramiel commented Feb 18, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants