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

Add the option to skip a query when using hooks #345

Closed
davidgtu opened this issue Apr 5, 2024 · 2 comments
Closed

Add the option to skip a query when using hooks #345

davidgtu opened this issue Apr 5, 2024 · 2 comments

Comments

@davidgtu
Copy link

davidgtu commented Apr 5, 2024

First off, thank you for making this library. As a long-time React developer and using graphql + codegen there, the introduction of useQuery hooks has made my developer experience so much smoother.

One thing I found helpful when using the generated useQuery hooks on the web side is that we have the option to skip a query. Here's the documentation on Apollo on its usage.

I'm using a hook that looks like this, all generated from this library:

final fetchChallengeDetailQuery = useQuery$FetchChallengeDetails(
  Options$Query$FetchChallengeDetails(
    fetchPolicy: FetchPolicy.networkOnly,
    variables: Variables$Query$FetchChallengeDetails(
      id: challengeId,
    ),
  ),
);

However, challengeId is type String? and id is looking for String. If I were to implement this in React, having the ability to skip the query if challengeId is null would help with compiling and error catching. I feel that this might be a good addition to this library. I would propose to add an optional field under options

final fetchChallengeDetailQuery = useQuery$FetchChallengeDetails(
  Options$Query$FetchChallengeDetails(
    skip: !challengeId,
    fetchPolicy: FetchPolicy.networkOnly,
    variables: Variables$Query$FetchChallengeDetails(
      id: challengeId,
    ),
  ),
);

So the hook wouldn't run if skip was true.

I would love to know your thoughts!

Copy link

github-actions bot commented Apr 5, 2024

👋 @davidgtu
Thank you for raising an issue. I will investigate the issue and get back to you as soon as possible.
Please make sure you have provided enough context.

This library is created and maintained by me, @budde377. Please consider supporting my work and ensure our survival by donating here.

@budde377
Copy link
Contributor

Thank you for creating this issue @davidgtu. I think the right approach would be to add this to the underlying GraphQL Flutter client and then add it here. In the mean time, have you tried the @skip directive?

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

2 participants