Skip to content

Conversation

@TkDodo
Copy link
Collaborator

@TkDodo TkDodo commented Aug 10, 2021

refs #1866

missing:

  • finalize api
  • tests
  • docs

@vercel
Copy link

vercel bot commented Aug 10, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/tannerlinsley/react-query/Cp49dNZ8MsyxQH5FBFjy9xBn7Wsu
✅ Preview: https://react-query-git-fork-tkdodo-feature-1866-r-2d50d2-tannerlinsley.vercel.app

@codesandbox-ci
Copy link

codesandbox-ci bot commented Aug 10, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 56a3e12:

Sandbox Source
tannerlinsley/react-query: basic Configuration
tannerlinsley/react-query: basic-typescript Configuration

this.queryCache.findAll(filters).map(query => query.fetch())
this.queryCache.findAll(filters).map(query =>
query.fetch(undefined, {
meta: { refetchPage: options?.refetchPage },
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I played around with this a bit, but I'm not in love with the public api. Two things:

  1. if you pass refetchPage on a normal useQuery (non-infinite-query), it doesn't do anything
  2. if you have a queryKey, but no filters, you'd need to do:
queryClient.invalidateQueries('myKey', undefined, {
    refetchPage: (page, allPages) => page === allPages[0]
})

yes, you could do:

queryClient.invalidateQueries({ queryKey: 'myKey' }, {
    refetchPage: (page, allPages) => page === allPages[0]
})

instead, but the same drawback applies when you want to invalidate everything:

queryClient.invalidateQueries(undefined, {
    refetchPage: (page, allPages) => page === allPages[0]
})

we could alternatively add that refetchPage option to queryFilters, similar to refetchActive and refetchInactive flags we can already provide to invalidateQueries. It's not really a query "filter" per se, because it doesn't narrow down anything, but neither is refetchActive, so maybe that distinction doesn't matter that much?


the only thing that comes to my mind to solve issue 1) would be a separate invalidateInfiniteQueries, but that would also mean we'd need refetchInfiniteQueries and resetInfiniteQueries with all the overloads and I don't think that's worth it.


right now, I would go with adding it to the query filters. What do you think @tannerlinsley ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found a reason to maybe keep the current api: the refetch method returned from useInfiniteQuery already takes RefetchOptions, so it's rather easy to make refetchPage work there as well

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I would prefer just adding to the query filters and having it be a noop for non-infinite queries. Thoughts?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, I can do that, let me see how that looks. Would we still want to have it as an option for refetch returned from useQuery ? I would say yes, and we could just add it to the options there as well

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you think?

56a3e12

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love it.

TkDodo added 3 commits August 14, 2021 20:55
…refetched

make refetchPage also be respected on the refetch function returned from useInfiniteQuery
…refetched

add possibility for types to flow through so that refetch from useInfiniteQuery will infer types of pages
…refetched

test for refetch method returned from useInfiniteQuery
TkDodo added 2 commits August 14, 2021 22:04
…refetched

add tests for refetchQueries and invalidateQueries
for invalidation, we also need to refetch inactiveQueries, because creating a new Observer doesn't add it as active to the client
…refetched

test for resetQueries, requires initialData
TkDodo added 2 commits August 14, 2021 22:33
…refetched

refetchPage signature now takes page, index, allPages

this is the same signature as e.g. Array.prototype.map
@TkDodo TkDodo marked this pull request as ready for review August 14, 2021 20:56
@TkDodo TkDodo requested a review from tannerlinsley August 14, 2021 20:56
…refetched

move refetchPage into queryFilters
@TkDodo TkDodo merged commit f9b23fc into TanStack:master Aug 20, 2021
@TkDodo TkDodo deleted the feature/1866-refetch-page branch August 20, 2021 14:19
@tannerlinsley
Copy link
Member

🎉 This PR is included in version 3.20.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants