-
Notifications
You must be signed in to change notification settings - Fork 1
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
feat!: upgrade to use @tanstack/react-query@v5 #44
Conversation
Merging this PR will result in a major version bump. Created by lifeomic-probot (Enforce Semantic Commits) |
9ae8c2e
to
493aa58
Compare
493aa58
to
aa2afb5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one question.
|
||
- The minimum required TypeScript version is now 4.7 | ||
|
||
- TypeScript: `Error` is now the default type for errors instead of `unknown` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's cool
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for sure! we could even globally override the default error value, if someone wanted to keep unknown
, or to an AxiosError
https://tanstack.com/query/v5/docs/framework/react/typescript#registering-a-global-error
since do rely on axios for this package we could make that assumption I suppose
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool!
|
||
- Removed `keepPreviousData` in favor of `placeholderData` identity function | ||
|
||
- Rename `cacheTime` to `gcTime` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a much better name
type RestrictedUseInfiniteQueryResult<Response, Request> = Omit< | ||
UseInfiniteQueryResult<Response>, | ||
'fetchNextPage' | 'fetchPreviousPage' | ||
> & { | ||
fetchNextPage: ( | ||
options?: Omit<FetchNextPageOptions, 'pageParam'> & { | ||
pageParam: Partial<Request>; | ||
}, | ||
) => Promise<InfiniteQueryObserverResult<Response>>; | ||
fetchPreviousPage: ( | ||
options?: Omit<FetchPreviousPageOptions, 'pageParam'> & { | ||
pageParam: Partial<Request>; | ||
}, | ||
) => Promise<InfiniteQueryObserverResult<Response>>; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this type going away?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@swain good question. We no longer need to override any of the types for the result of useInfiniteAPIQuery
As part of the v5 migration guide they make it clear that they no longer allow passing pageParam through fetchNextPage
or fetchPreviousPage
. see here
There main reasoning being
This feature didn't work at all with refetches and wasn't widely known or used
so we can rely on the default types for these methods
ProposalThis PR does not include this change - but you can view some code changes to get an idea at #45. it is incomplete and only makes the change for To Better align with with the api changes in react-query, I proposed that the api change to providing the request "input" or - useAPIQuery(route, payload, options)
+ useAPIQuery(route, { payload, ...options }) This is mostly to try to come closer to the api react-query exposes. in v5 all hooks now take a single This was proposed to a small group and receptions were mixed so interested to hear others ideas. Here are some brief notes. Was curious if anyone else has had thoughts
|
|
||
- Removed `refetchPage` in favor of `maxPages` | ||
|
||
- The experimental `suspense: boolean` flag on the query hooks has been removed - new hooks for suspense have been added |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see #43
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work!
.request(route, payload, options?.axios) | ||
.then((res) => res.data); | ||
.request(route, payload, options.axios) | ||
.then((res) => res.data) as any; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did we need this new cast here? It seems like it was strongly typed before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll see if I can fix this up in a follow up. Types have changed quite a bit in latest
@@ -92,7 +100,7 @@ export const createAPIHooks = <Endpoints extends RoughEndpoints>({ | |||
client | |||
.request(endpoint, payload, options?.axios) | |||
.then((res) => res.data), | |||
})), | |||
})) as [...QueriesOptions<any>], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. Why did we lose the strong typing we had before? I think it's worth commenting on why we need the explicit casts now if there's no way around it.
@@ -1,3 +1,4 @@ | |||
/* eslint-disable @typescript-eslint/ban-ts-comment */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, @ts-expect-error
is used many times below with comments, but now need to disable the eslint rule too
This document provides instructions for upgrading between major | ||
versions of `@lifeomic/one-query` | ||
|
||
### 3.x -> 4.x |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be 4.x -> 5.x
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
react-query went from 4 to 5, but v4 will be the next major version of one-query
🎉 This PR is included in version 4.0.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Motivation
This pr makes the breaking change adopting @tanstack/react-query@v5
It includes
DefaultError
overunknown
(react-query has a way to over ride it to change it fromError
)loading
=>pending
useQuery
have been removed (e.g.,onSuccess
,onError
andonSettled
)cacheTime
=>gcTime
refetchPage
=>maxPages
Next Steps
This allows us to now support api typed suspense hooks that are available in
@tanstack/react-query@v5