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

reexecuteQuery for jotai/urql #666

Closed
etodanik opened this issue Aug 19, 2021 · 14 comments · Fixed by #668
Closed

reexecuteQuery for jotai/urql #666

etodanik opened this issue Aug 19, 2021 · 14 comments · Fixed by #668

Comments

@etodanik
Copy link
Contributor

Do I understand correctly that there is no mechanism at all to reexecute a query in jotai/urql? In the regular urql hooks there is this method:
https://formidable.com/open-source/urql/docs/basics/react-preact/#reexecuting-queries

const Todos = ({ from, limit }) => {
  const [result, reexecuteQuery] = useQuery({
    query: TodosListQuery,
    variables: { from, limit },
  });

  const refresh = () => {
    // Refetch the query and skip the cache
    reexecuteQuery({ requestPolicy: 'network-only' });
  };
};

Not being able to reexecute queries seems like a rather big limitation.

@dai-shi
Copy link
Member

dai-shi commented Aug 19, 2021

I wasn't aware the reexecute feature. I don't know how I missed it. We have "refetch" feature in jotai/query. So, we should follow the pattern.

@dai-shi
Copy link
Member

dai-shi commented Aug 20, 2021

Actually, it doesn't work like jotai/query. 🤔

@etodanik
Copy link
Contributor Author

etodanik commented Aug 20, 2021 via email

@etodanik
Copy link
Contributor Author

etodanik commented Aug 20, 2021 via email

@dai-shi
Copy link
Member

dai-shi commented Aug 20, 2021

Please try if https://ci.codesandbox.io/status/pmndrs/jotai/pr/668 works.

@dai-shi
Copy link
Member

dai-shi commented Aug 22, 2021

So Im available to contribute

Well, I should have asked for your help from the beginning. Next time.

I will merge #668 soon.

@etodanik
Copy link
Contributor Author

@dai-shi I'll test it today & let you know that it works!

@dai-shi
Copy link
Member

dai-shi commented Aug 24, 2021

Okay, I will wait. (I was about to cut a release.)

@dai-shi
Copy link
Member

dai-shi commented Aug 25, 2021

Well, I think we can release it, and if something goes wrong, we'll fix it ASAP.

@etodanik
Copy link
Contributor Author

I tested it, the refetching it self seems to work, but if I understand correctly, I now can't know about the fact that it is refetching/refreshing? In vanilla urql there is the fetching variable which is part of the result. What would be the pattern to know we're refetching in this new update?

@dai-shi
Copy link
Member

dai-shi commented Aug 25, 2021

Yeah, that was my question too actually. For now, it will throw a promise, so it suspends on refetch just like the first fetch, right? This behavior is consistent with atomWithQuery in jotai/query.
I think we never used fetching variable in favor of Suspense. Does vanilla urql have fetching?

@etodanik
Copy link
Contributor Author

etodanik commented Aug 25, 2021

@dai-shi vanilla urql indeed has fetching returned as part of the result object (https://formidable.com/open-source/urql/docs/api/urql/#usequery). I can think of quite a lot of use cases where for a query having a fetching variable would be useful vs. a thrown Promise, especially on second and subsequent loads. A degree of control (suspend vs. non-suspend) could be useful, what do you think?

For example, in my current use-case with React Native, the actually has a refreshing prop (https://reactnative.dev/docs/flatlist#refreshing) that triggers a much more sophisticated experience than just eliminating the list and showing a loading indicator fallback. It implements the whole "drag to refresh" dynamic.

Another example is when an initial load is done on something like a feed & you'd want to fetch in the background and only re-rendering if new items appear without indicating a loader to the user.

@dai-shi
Copy link
Member

dai-shi commented Aug 26, 2021

Yeah, fetching is in react-urql.
jotai atoms are designed for Suspense and useTransition, which might be too futuristic for now.
I understand that distinguishing between the initial fetching and refetching is important in the real use case. We hope to come up with some ideas for both jotai/urql and jotai/query.
btw, you might be interested in the new util at #672. Actually, it could solve refetching issue there.

Apart from jotai, I wonder how drag to refersh and background refetch will be implemented as best practices in Suspense era.

@etodanik
Copy link
Contributor Author

etodanik commented Aug 26, 2021 via email

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

Successfully merging a pull request may close this issue.

2 participants