-
Notifications
You must be signed in to change notification settings - Fork 215
@W-17917528 Upgrade to @tanstack/react-query v5 #2303
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
Changes from all commits
1271128
da598a9
54f61e1
48c3070
3d3cd8c
27eddf2
818d494
1d1c165
bbbfda5
d4b66ff
6c5ffe9
df28643
4a0d936
0908080
de0e7b4
5ef692b
989cbf8
52db136
850e678
d4b2883
41f5f41
9d1b9de
85f74ba
8c82322
3759a0d
c49a78b
f1afa3c
77f0cf9
8ac8d5a
7c2796e
b391d92
9fc0d48
1e5740e
34f33db
9c15553
d5f0b67
70bb253
7bc7410
91bf448
cc66573
5e90a94
ac25a35
69d5580
c05b937
68daa41
1cbea68
c79d607
0aa24cf
fd52e61
76c92dc
aa729dd
3f69f15
6a6a463
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
| * SPDX-License-Identifier: BSD-3-Clause | ||
| * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
| */ | ||
| /* eslint-disable @typescript-eslint/ban-ts-comment */ | ||
kevinxh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| import {UseQueryResult} from '@tanstack/react-query' | ||
| import {ApiClients, ApiQueryOptions, Argument, DataType, NullableParameters} from '../types' | ||
| import useCommerceApi from '../useCommerceApi' | ||
|
|
@@ -28,7 +29,7 @@ type Client = ApiClients['shopperBaskets'] | |
| export const useBasket = ( | ||
| apiOptions: NullableParameters<Argument<Client['getBasket']>>, | ||
| queryOptions: ApiQueryOptions<Client['getBasket']> = {} | ||
| ): UseQueryResult<DataType<Client['getBasket']>> => { | ||
| ): UseQueryResult<DataType<Client['getBasket']>, Error> => { | ||
| type Options = Argument<Client['getBasket']> | ||
| type Data = DataType<Client['getBasket']> | ||
| const {shopperBaskets: client} = useCommerceApi() | ||
|
|
@@ -50,6 +51,7 @@ export const useBasket = ( | |
|
|
||
| // For some reason, if we don't explicitly set these generic parameters, the inferred type for | ||
| // `Data` sometimes, but not always, includes `Response`, which is incorrect. I don't know why. | ||
| // @ts-ignore Fix | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new react-query v5 had a MAJOR overhaul of its type definitions, including removing of tons of overloads. Now, only one function signature type is available, which is a super good news for us, because in the past, we've had issues to create types that satisfy all of the overloads. This was a major blocker for us creating a DRY implementation, and we had to duplicate the implementation for every Shopper api. I'm going to create a new ticket to re-implement the useQuery and useMutation typings and hopefully we can use generics to DRY the implementation. This would also drastically decrease the bundle size. Ticket to be created. |
||
| return useQuery<Client, Options, Data>({...netOptions, parameters}, queryOptions, { | ||
| method, | ||
| queryKey, | ||
|
|
@@ -70,7 +72,7 @@ export const useBasket = ( | |
| export const usePaymentMethodsForBasket = ( | ||
| apiOptions: NullableParameters<Argument<Client['getPaymentMethodsForBasket']>>, | ||
| queryOptions: ApiQueryOptions<Client['getPaymentMethodsForBasket']> = {} | ||
| ): UseQueryResult<DataType<Client['getPaymentMethodsForBasket']>> => { | ||
| ): UseQueryResult<DataType<Client['getPaymentMethodsForBasket']>, Error> => { | ||
| type Options = Argument<Client['getPaymentMethodsForBasket']> | ||
| type Data = DataType<Client['getPaymentMethodsForBasket']> | ||
| const {shopperBaskets: client} = useCommerceApi() | ||
|
|
@@ -92,6 +94,7 @@ export const usePaymentMethodsForBasket = ( | |
|
|
||
| // For some reason, if we don't explicitly set these generic parameters, the inferred type for | ||
| // `Data` sometimes, but not always, includes `Response`, which is incorrect. I don't know why. | ||
| // @ts-ignore TODO: Fix react query result error generics | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the reason we have having this issue? Is you plan to ignore it or will this be fixed in this PR. Or will it be fixed in the refactor ticket you mentioned in a previous comment. |
||
| return useQuery<Client, Options, Data>({...netOptions, parameters}, queryOptions, { | ||
| method, | ||
| queryKey, | ||
|
|
@@ -112,7 +115,7 @@ export const usePaymentMethodsForBasket = ( | |
| export const usePriceBooksForBasket = ( | ||
| apiOptions: NullableParameters<Argument<Client['getPriceBooksForBasket']>>, | ||
| queryOptions: ApiQueryOptions<Client['getPriceBooksForBasket']> = {} | ||
| ): UseQueryResult<DataType<Client['getPriceBooksForBasket']>> => { | ||
| ): UseQueryResult<DataType<Client['getPriceBooksForBasket']>, Error> => { | ||
| type Options = Argument<Client['getPriceBooksForBasket']> | ||
| type Data = DataType<Client['getPriceBooksForBasket']> | ||
| const {shopperBaskets: client} = useCommerceApi() | ||
|
|
@@ -134,6 +137,7 @@ export const usePriceBooksForBasket = ( | |
|
|
||
| // For some reason, if we don't explicitly set these generic parameters, the inferred type for | ||
| // `Data` sometimes, but not always, includes `Response`, which is incorrect. I don't know why. | ||
| // @ts-ignore TODO: Fix react query result error generics | ||
| return useQuery<Client, Options, Data>({...netOptions, parameters}, queryOptions, { | ||
| method, | ||
| queryKey, | ||
|
|
@@ -154,7 +158,7 @@ export const usePriceBooksForBasket = ( | |
| export const useShippingMethodsForShipment = ( | ||
| apiOptions: NullableParameters<Argument<Client['getShippingMethodsForShipment']>>, | ||
| queryOptions: ApiQueryOptions<Client['getShippingMethodsForShipment']> = {} | ||
| ): UseQueryResult<DataType<Client['getShippingMethodsForShipment']>> => { | ||
| ): UseQueryResult<DataType<Client['getShippingMethodsForShipment']>, Error> => { | ||
| type Options = Argument<Client['getShippingMethodsForShipment']> | ||
| type Data = DataType<Client['getShippingMethodsForShipment']> | ||
| const {shopperBaskets: client} = useCommerceApi() | ||
|
|
@@ -176,6 +180,7 @@ export const useShippingMethodsForShipment = ( | |
|
|
||
| // For some reason, if we don't explicitly set these generic parameters, the inferred type for | ||
| // `Data` sometimes, but not always, includes `Response`, which is incorrect. I don't know why. | ||
| // @ts-ignore TODO: Fix react query result error generics | ||
| return useQuery<Client, Options, Data>({...netOptions, parameters}, queryOptions, { | ||
| method, | ||
| queryKey, | ||
|
|
@@ -196,7 +201,7 @@ export const useShippingMethodsForShipment = ( | |
| export const useTaxesFromBasket = ( | ||
| apiOptions: NullableParameters<Argument<Client['getTaxesFromBasket']>>, | ||
| queryOptions: ApiQueryOptions<Client['getTaxesFromBasket']> = {} | ||
| ): UseQueryResult<DataType<Client['getTaxesFromBasket']>> => { | ||
| ): UseQueryResult<DataType<Client['getTaxesFromBasket']>, Error> => { | ||
| type Options = Argument<Client['getTaxesFromBasket']> | ||
| type Data = DataType<Client['getTaxesFromBasket']> | ||
| const {shopperBaskets: client} = useCommerceApi() | ||
|
|
@@ -218,6 +223,7 @@ export const useTaxesFromBasket = ( | |
|
|
||
| // For some reason, if we don't explicitly set these generic parameters, the inferred type for | ||
| // `Data` sometimes, but not always, includes `Response`, which is incorrect. I don't know why. | ||
| // @ts-ignore TODO: Fix react query result error generics | ||
| return useQuery<Client, Options, Data>({...netOptions, parameters}, queryOptions, { | ||
| method, | ||
| queryKey, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.