Skip to content

Commit c9834b6

Browse files
authoredMar 18, 2024
fix(vue): update samples to v5 and fix type issue (#1268)
1 parent b03d0fd commit c9834b6

File tree

4 files changed

+118
-79
lines changed

4 files changed

+118
-79
lines changed
 

‎packages/query/src/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1110,9 +1110,9 @@ ${doc}export const ${camel(
11101110
`${operationPrefix}-${type}`,
11111111
)}(${queryOptionsVarName}) as ${returnType};
11121112
1113-
${queryResultVarName}.queryKey = ${queryOptionsVarName}.queryKey ${
1114-
isVue(outputClient) ? 'as QueryKey' : ''
1115-
};
1113+
${queryResultVarName}.queryKey = ${
1114+
isVue(outputClient) ? `unref(${queryOptionsVarName})` : queryOptionsVarName
1115+
}.queryKey ${isVue(outputClient) ? 'as QueryKey' : ''};
11161116
11171117
return ${queryResultVarName};
11181118
}\n

‎samples/vue-query/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
},
1414
"dependencies": {
1515
"@faker-js/faker": "^8.0.2",
16-
"@tanstack/vue-query": "4.29.5",
16+
"@tanstack/vue-query": "^5.28.4",
1717
"axios": "^0.26.1",
1818
"vue": "^3.3.4"
1919
},

‎samples/vue-query/src/api/endpoints/petstoreFromFileSpecWithTransformer.ts

+62-45
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77
import { useInfiniteQuery, useMutation, useQuery } from '@tanstack/vue-query';
88
import type {
9+
InfiniteData,
910
MutationFunction,
1011
QueryFunction,
1112
QueryKey,
@@ -54,27 +55,36 @@ export const getListPetsQueryKey = (
5455
};
5556

5657
export const getListPetsInfiniteQueryOptions = <
57-
TData = Awaited<ReturnType<typeof listPets>>,
58+
TData = InfiniteData<
59+
Awaited<ReturnType<typeof listPets>>,
60+
ListPetsParams['limit']
61+
>,
5862
TError = Error,
5963
>(
6064
params?: MaybeRef<ListPetsParams>,
6165
version: MaybeRef<number | undefined | null> = 1,
6266
options?: {
63-
query?: UseInfiniteQueryOptions<
64-
Awaited<ReturnType<typeof listPets>>,
65-
TError,
66-
TData
67+
query?: Partial<
68+
UseInfiniteQueryOptions<
69+
Awaited<ReturnType<typeof listPets>>,
70+
TError,
71+
TData,
72+
Awaited<ReturnType<typeof listPets>>,
73+
QueryKey,
74+
ListPetsParams['limit']
75+
>
6776
>;
6877
},
6978
) => {
7079
const { query: queryOptions } = options ?? {};
7180

7281
const queryKey = getListPetsQueryKey(params, version);
7382

74-
const queryFn: QueryFunction<Awaited<ReturnType<typeof listPets>>> = ({
75-
signal,
76-
pageParam,
77-
}) =>
83+
const queryFn: QueryFunction<
84+
Awaited<ReturnType<typeof listPets>>,
85+
QueryKey,
86+
ListPetsParams['limit']
87+
> = ({ signal, pageParam }) =>
7888
listPets(
7989
{ ...params, limit: pageParam || unref(params)?.['limit'] },
8090
version,
@@ -89,7 +99,10 @@ export const getListPetsInfiniteQueryOptions = <
8999
} as UseInfiniteQueryOptions<
90100
Awaited<ReturnType<typeof listPets>>,
91101
TError,
92-
TData
102+
TData,
103+
Awaited<ReturnType<typeof listPets>>,
104+
QueryKey,
105+
ListPetsParams['limit']
93106
>;
94107
};
95108

@@ -102,16 +115,24 @@ export type ListPetsInfiniteQueryError = Error;
102115
* @summary List all pets
103116
*/
104117
export const useListPetsInfinite = <
105-
TData = Awaited<ReturnType<typeof listPets>>,
118+
TData = InfiniteData<
119+
Awaited<ReturnType<typeof listPets>>,
120+
ListPetsParams['limit']
121+
>,
106122
TError = Error,
107123
>(
108124
params?: MaybeRef<ListPetsParams>,
109125
version: MaybeRef<number | undefined | null> = 1,
110126
options?: {
111-
query?: UseInfiniteQueryOptions<
112-
Awaited<ReturnType<typeof listPets>>,
113-
TError,
114-
TData
127+
query?: Partial<
128+
UseInfiniteQueryOptions<
129+
Awaited<ReturnType<typeof listPets>>,
130+
TError,
131+
TData,
132+
Awaited<ReturnType<typeof listPets>>,
133+
QueryKey,
134+
ListPetsParams['limit']
135+
>
115136
>;
116137
},
117138
): UseInfiniteQueryReturnType<TData, TError> & { queryKey: QueryKey } => {
@@ -126,7 +147,7 @@ export const useListPetsInfinite = <
126147
TError
127148
> & { queryKey: QueryKey };
128149

129-
query.queryKey = queryOptions.queryKey as QueryKey;
150+
query.queryKey = unref(queryOptions).queryKey as QueryKey;
130151

131152
return query;
132153
};
@@ -138,10 +159,8 @@ export const getListPetsQueryOptions = <
138159
params?: MaybeRef<ListPetsParams>,
139160
version: MaybeRef<number | undefined | null> = 1,
140161
options?: {
141-
query?: UseQueryOptions<
142-
Awaited<ReturnType<typeof listPets>>,
143-
TError,
144-
TData
162+
query?: Partial<
163+
UseQueryOptions<Awaited<ReturnType<typeof listPets>>, TError, TData>
145164
>;
146165
},
147166
) => {
@@ -176,10 +195,8 @@ export const useListPets = <
176195
params?: MaybeRef<ListPetsParams>,
177196
version: MaybeRef<number | undefined | null> = 1,
178197
options?: {
179-
query?: UseQueryOptions<
180-
Awaited<ReturnType<typeof listPets>>,
181-
TError,
182-
TData
198+
query?: Partial<
199+
UseQueryOptions<Awaited<ReturnType<typeof listPets>>, TError, TData>
183200
>;
184201
},
185202
): UseQueryReturnType<TData, TError> & { queryKey: QueryKey } => {
@@ -189,7 +206,7 @@ export const useListPets = <
189206
queryKey: QueryKey;
190207
};
191208

192-
query.queryKey = queryOptions.queryKey as QueryKey;
209+
query.queryKey = unref(queryOptions).queryKey as QueryKey;
193210

194211
return query;
195212
};
@@ -297,16 +314,18 @@ export const getShowPetByIdQueryKey = (
297314
};
298315

299316
export const getShowPetByIdInfiniteQueryOptions = <
300-
TData = Awaited<ReturnType<typeof showPetById>>,
317+
TData = InfiniteData<Awaited<ReturnType<typeof showPetById>>>,
301318
TError = Error,
302319
>(
303320
petId: MaybeRef<string | undefined | null>,
304321
version: MaybeRef<number | undefined | null> = 1,
305322
options?: {
306-
query?: UseInfiniteQueryOptions<
307-
Awaited<ReturnType<typeof showPetById>>,
308-
TError,
309-
TData
323+
query?: Partial<
324+
UseInfiniteQueryOptions<
325+
Awaited<ReturnType<typeof showPetById>>,
326+
TError,
327+
TData
328+
>
310329
>;
311330
},
312331
) => {
@@ -339,16 +358,18 @@ export type ShowPetByIdInfiniteQueryError = Error;
339358
* @summary Info for a specific pet
340359
*/
341360
export const useShowPetByIdInfinite = <
342-
TData = Awaited<ReturnType<typeof showPetById>>,
361+
TData = InfiniteData<Awaited<ReturnType<typeof showPetById>>>,
343362
TError = Error,
344363
>(
345364
petId: MaybeRef<string | undefined | null>,
346365
version: MaybeRef<number | undefined | null> = 1,
347366
options?: {
348-
query?: UseInfiniteQueryOptions<
349-
Awaited<ReturnType<typeof showPetById>>,
350-
TError,
351-
TData
367+
query?: Partial<
368+
UseInfiniteQueryOptions<
369+
Awaited<ReturnType<typeof showPetById>>,
370+
TError,
371+
TData
372+
>
352373
>;
353374
},
354375
): UseInfiniteQueryReturnType<TData, TError> & { queryKey: QueryKey } => {
@@ -363,7 +384,7 @@ export const useShowPetByIdInfinite = <
363384
TError
364385
> & { queryKey: QueryKey };
365386

366-
query.queryKey = queryOptions.queryKey as QueryKey;
387+
query.queryKey = unref(queryOptions).queryKey as QueryKey;
367388

368389
return query;
369390
};
@@ -375,10 +396,8 @@ export const getShowPetByIdQueryOptions = <
375396
petId: MaybeRef<string | undefined | null>,
376397
version: MaybeRef<number | undefined | null> = 1,
377398
options?: {
378-
query?: UseQueryOptions<
379-
Awaited<ReturnType<typeof showPetById>>,
380-
TError,
381-
TData
399+
query?: Partial<
400+
UseQueryOptions<Awaited<ReturnType<typeof showPetById>>, TError, TData>
382401
>;
383402
},
384403
) => {
@@ -413,10 +432,8 @@ export const useShowPetById = <
413432
petId: MaybeRef<string | undefined | null>,
414433
version: MaybeRef<number | undefined | null> = 1,
415434
options?: {
416-
query?: UseQueryOptions<
417-
Awaited<ReturnType<typeof showPetById>>,
418-
TError,
419-
TData
435+
query?: Partial<
436+
UseQueryOptions<Awaited<ReturnType<typeof showPetById>>, TError, TData>
420437
>;
421438
},
422439
): UseQueryReturnType<TData, TError> & { queryKey: QueryKey } => {
@@ -426,7 +443,7 @@ export const useShowPetById = <
426443
queryKey: QueryKey;
427444
};
428445

429-
query.queryKey = queryOptions.queryKey as QueryKey;
446+
query.queryKey = unref(queryOptions).queryKey as QueryKey;
430447

431448
return query;
432449
};

‎samples/vue-query/yarn.lock

+52-30
Original file line numberDiff line numberDiff line change
@@ -296,27 +296,27 @@
296296
resolved "https://registry.yarnpkg.com/@sinclair/typebox/-/typebox-0.27.8.tgz#6667fac16c436b5434a387a34dedb013198f6e6e"
297297
integrity sha512-+Fj43pSMwJs4KRrH/938Uf+uAELIgVBmQzg/q1YG10djyfA3TnrU8N8XzqCh/okZdszqBQTZf96idMfE5lnwTA==
298298

299-
"@tanstack/match-sorter-utils@^8.1.1":
300-
version "8.7.6"
301-
resolved "https://registry.yarnpkg.com/@tanstack/match-sorter-utils/-/match-sorter-utils-8.7.6.tgz#ccf54a37447770e0cf0fe49a579c595fd2655b16"
302-
integrity sha512-2AMpRiA6QivHOUiBpQAVxjiHAA68Ei23ZUMNaRJrN6omWiSFLoYrxGcT6BXtuzp0Jw4h6HZCmGGIM/gbwebO2A==
299+
"@tanstack/match-sorter-utils@^8.11.8":
300+
version "8.11.8"
301+
resolved "https://registry.yarnpkg.com/@tanstack/match-sorter-utils/-/match-sorter-utils-8.11.8.tgz#9132c2a21cf18ca2f0071b604ddadb7a66e73367"
302+
integrity sha512-3VPh0SYMGCa5dWQEqNab87UpCMk+ANWHDP4ALs5PeEW9EpfTAbrezzaOk/OiM52IESViefkoAOYuxdoa04p6aA==
303303
dependencies:
304304
remove-accents "0.4.2"
305305

306-
"@tanstack/query-core@4.29.5":
307-
version "4.29.5"
308-
resolved "https://registry.yarnpkg.com/@tanstack/query-core/-/query-core-4.29.5.tgz#a0273e88bf2fc102c4c893dc7c034127b67fd5d9"
309-
integrity sha512-xXIiyQ/4r9KfaJ3k6kejqcaqFXXBTzN2aOJ5H1J6aTJE9hl/nbgAdfF6oiIu0CD5xowejJEJ6bBg8TO7BN4NuQ==
306+
"@tanstack/query-core@5.28.4":
307+
version "5.28.4"
308+
resolved "https://registry.yarnpkg.com/@tanstack/query-core/-/query-core-5.28.4.tgz#fa416532f8b33ca8608d40bb9728b60e2e1a38dc"
309+
integrity sha512-uQZqOFqLWUvXNIQZ63XdKzg22NtHzgCBUfDmjDHi3BoF+nUYeBNvMi/xFPtFrMhqRzG2Ir4mYaGsWZzmiEjXpA==
310310

311-
"@tanstack/vue-query@4.29.5":
312-
version "4.29.5"
313-
resolved "https://registry.yarnpkg.com/@tanstack/vue-query/-/vue-query-4.29.5.tgz#a6795e0e86fb6c58e09fa38775ca2f6e4f8f5fda"
314-
integrity sha512-o5EqXKG/SbOcqDxc0LHNMQvB/77dFTRL9EdfFKXUHGIFGhKDhuiA0ByT/HydzXWzj7oGj44ovosAusej90yKVg==
311+
"@tanstack/vue-query@^5.28.4":
312+
version "5.28.4"
313+
resolved "https://registry.yarnpkg.com/@tanstack/vue-query/-/vue-query-5.28.4.tgz#41d9d4bcb2186b3c58db41141f2a4c3e5d1524c0"
314+
integrity sha512-/xt4CmP/0NHN5FDtt1uvh+aXm8uHDos7gsXlDr5l6Ul5pkN9eByd86PqEkiRxgrZcuHvcB5RXSaiagxOIgoByg==
315315
dependencies:
316-
"@tanstack/match-sorter-utils" "^8.1.1"
317-
"@tanstack/query-core" "4.29.5"
318-
"@vue/devtools-api" "^6.4.2"
319-
vue-demi "^0.13.11"
316+
"@tanstack/match-sorter-utils" "^8.11.8"
317+
"@tanstack/query-core" "5.28.4"
318+
"@vue/devtools-api" "^6.5.1"
319+
vue-demi "^0.14.6"
320320

321321
"@testing-library/dom@^9.3.3":
322322
version "9.3.3"
@@ -566,10 +566,10 @@
566566
"@vue/compiler-dom" "3.3.4"
567567
"@vue/shared" "3.3.4"
568568

569-
"@vue/devtools-api@^6.4.2":
570-
version "6.4.5"
571-
resolved "https://registry.yarnpkg.com/@vue/devtools-api/-/devtools-api-6.4.5.tgz#d54e844c1adbb1e677c81c665ecef1a2b4bb8380"
572-
integrity sha512-JD5fcdIuFxU4fQyXUu3w2KpAJHzTVdN+p4iOX2lMWSHMOoQdMAcpFLZzm9Z/2nmsoZ1a96QEhZ26e50xLBsgOQ==
569+
"@vue/devtools-api@^6.5.1":
570+
version "6.6.1"
571+
resolved "https://registry.yarnpkg.com/@vue/devtools-api/-/devtools-api-6.6.1.tgz#7c14346383751d9f6ad4bea0963245b30220ef83"
572+
integrity sha512-LgPscpE3Vs0x96PzSSB4IGVSZXZBZHpfxs+ZA1d+VEPwHdOXowy/Y2CsvCAIFrf+ssVU1pD1jidj505EpUnfbA==
573573

574574
"@vue/language-core@1.8.18":
575575
version "1.8.18"
@@ -2740,8 +2740,7 @@ strict-event-emitter@^0.5.0, strict-event-emitter@^0.5.1:
27402740
resolved "https://registry.yarnpkg.com/strict-event-emitter/-/strict-event-emitter-0.5.1.tgz#1602ece81c51574ca39c6815e09f1a3e8550bd93"
27412741
integrity sha512-vMgjE/GGEPEFnhFub6pa4FmJBRBVOLpIII2hvCZ8Kzb7K0hlHo7mQv6xYrBvCL2LtAIBwFUK8wvuJgTVSQ5MFQ==
27422742

2743-
"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.2.3:
2744-
name string-width-cjs
2743+
"string-width-cjs@npm:string-width@^4.2.0":
27452744
version "4.2.3"
27462745
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
27472746
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
@@ -2759,6 +2758,15 @@ string-width@^4.1.0, string-width@^4.2.0:
27592758
is-fullwidth-code-point "^3.0.0"
27602759
strip-ansi "^6.0.0"
27612760

2761+
string-width@^4.2.3:
2762+
version "4.2.3"
2763+
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
2764+
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
2765+
dependencies:
2766+
emoji-regex "^8.0.0"
2767+
is-fullwidth-code-point "^3.0.0"
2768+
strip-ansi "^6.0.1"
2769+
27622770
string-width@^5.0.1, string-width@^5.1.2:
27632771
version "5.1.2"
27642772
resolved "https://registry.yarnpkg.com/string-width/-/string-width-5.1.2.tgz#14f8daec6d81e7221d2a357e668cab73bdbca794"
@@ -2775,8 +2783,7 @@ string_decoder@^1.1.1:
27752783
dependencies:
27762784
safe-buffer "~5.2.0"
27772785

2778-
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.1:
2779-
name strip-ansi-cjs
2786+
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
27802787
version "6.0.1"
27812788
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
27822789
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
@@ -2790,6 +2797,13 @@ strip-ansi@^6.0.0:
27902797
dependencies:
27912798
ansi-regex "^5.0.0"
27922799

2800+
strip-ansi@^6.0.1:
2801+
version "6.0.1"
2802+
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
2803+
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
2804+
dependencies:
2805+
ansi-regex "^5.0.1"
2806+
27932807
strip-ansi@^7.0.1:
27942808
version "7.1.0"
27952809
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-7.1.0.tgz#d5b6568ca689d8561370b0707685d22434faff45"
@@ -3051,10 +3065,10 @@ vue-component-type-helpers@^1.8.21:
30513065
resolved "https://registry.yarnpkg.com/vue-component-type-helpers/-/vue-component-type-helpers-1.8.22.tgz#24c1f324885e5652c7bcc5d9cbd76800b0af3809"
30523066
integrity sha512-LK3wJHs3vJxHG292C8cnsRusgyC5SEZDCzDCD01mdE/AoREFMl2tzLRuzwyuEsOIz13tqgBcnvysN3Lxsa14Fw==
30533067

3054-
vue-demi@^0.13.11:
3055-
version "0.13.11"
3056-
resolved "https://registry.yarnpkg.com/vue-demi/-/vue-demi-0.13.11.tgz#7d90369bdae8974d87b1973564ad390182410d99"
3057-
integrity sha512-IR8HoEEGM65YY3ZJYAjMlKygDQn25D5ajNFNoKh9RSDMQtlzCxtfQjdQgv9jjK+m3377SsJXY8ysq8kLCZL25A==
3068+
vue-demi@^0.14.6:
3069+
version "0.14.7"
3070+
resolved "https://registry.yarnpkg.com/vue-demi/-/vue-demi-0.14.7.tgz#8317536b3ef74c5b09f268f7782e70194567d8f2"
3071+
integrity sha512-EOG8KXDQNwkJILkx/gPcoL/7vH+hORoBaKgGe+6W7VFMvCYJfmF2dGbvgDroVnI8LU7/kTu8mbjRZGBU1z9NTA==
30583072

30593073
vue-template-compiler@^2.7.14:
30603074
version "2.7.14"
@@ -3188,8 +3202,7 @@ why-is-node-running@^2.2.2:
31883202
siginfo "^2.0.0"
31893203
stackback "0.0.2"
31903204

3191-
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
3192-
name wrap-ansi-cjs
3205+
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
31933206
version "7.0.0"
31943207
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
31953208
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
@@ -3207,6 +3220,15 @@ wrap-ansi@^6.0.1:
32073220
string-width "^4.1.0"
32083221
strip-ansi "^6.0.0"
32093222

3223+
wrap-ansi@^7.0.0:
3224+
version "7.0.0"
3225+
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
3226+
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
3227+
dependencies:
3228+
ansi-styles "^4.0.0"
3229+
string-width "^4.1.0"
3230+
strip-ansi "^6.0.0"
3231+
32103232
wrap-ansi@^8.1.0:
32113233
version "8.1.0"
32123234
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"

0 commit comments

Comments
 (0)
Please sign in to comment.