tangled
alpha
login
or
join now
mokkenstorm.dev
/
openapi-ts
0
fork
atom
fork of hey-api/openapi-ts because I need some additional things
0
fork
atom
overview
issues
pulls
pipelines
chore(pinia-colada): simplify example
Dmitriy Brolnickij
6 months ago
33516370
7eabf670
+22
-49
3 changed files
expand all
collapse all
unified
split
examples
openapi-ts-pinia-colada
openapi-ts.config.ts
src
client
@pinia
colada.gen.ts
views
PiniaColadaExample.vue
+2
-1
examples/openapi-ts-pinia-colada/openapi-ts.config.ts
···
18
18
},
19
19
{
20
20
exportFromIndex: true,
21
21
-
name: '@pinia/colada'
21
21
+
name: '@pinia/colada',
22
22
+
queryKeys: false
22
23
}
23
24
]
24
25
})
+8
-32
examples/openapi-ts-pinia-colada/src/client/@pinia/colada.gen.ts
···
118
118
return [params]
119
119
}
120
120
121
121
-
export const findPetsByStatusQueryKey = (options: Options<FindPetsByStatusData>) =>
122
122
-
createQueryKey('findPetsByStatus', options)
123
123
-
124
121
/**
125
122
* Finds Pets by status.
126
123
* Multiple status values can be provided with comma separated strings.
127
124
*/
128
125
export const findPetsByStatusQuery = defineQueryOptions(
129
126
(options: Options<FindPetsByStatusData>) => ({
130
130
-
key: findPetsByStatusQueryKey(options),
127
127
+
key: createQueryKey('findPetsByStatus', options),
131
128
query: async (context) => {
132
129
const { data } = await findPetsByStatus({
133
130
...options,
···
139
136
})
140
137
)
141
138
142
142
-
export const findPetsByTagsQueryKey = (options: Options<FindPetsByTagsData>) =>
143
143
-
createQueryKey('findPetsByTags', options)
144
144
-
145
139
/**
146
140
* Finds Pets by tags.
147
141
* Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
148
142
*/
149
143
export const findPetsByTagsQuery = defineQueryOptions((options: Options<FindPetsByTagsData>) => ({
150
150
-
key: findPetsByTagsQueryKey(options),
144
144
+
key: createQueryKey('findPetsByTags', options),
151
145
query: async (context) => {
152
146
const { data } = await findPetsByTags({
153
147
...options,
···
175
169
}
176
170
})
177
171
178
178
-
export const getPetByIdQueryKey = (options: Options<GetPetByIdData>) =>
179
179
-
createQueryKey('getPetById', options)
180
180
-
181
172
/**
182
173
* Find pet by ID.
183
174
* Returns a single pet.
184
175
*/
185
176
export const getPetByIdQuery = defineQueryOptions((options: Options<GetPetByIdData>) => ({
186
186
-
key: getPetByIdQueryKey(options),
177
177
+
key: createQueryKey('getPetById', options),
187
178
query: async (context) => {
188
179
const { data } = await getPetById({
189
180
...options,
···
228
219
}
229
220
})
230
221
231
231
-
export const getInventoryQueryKey = (options?: Options<GetInventoryData>) =>
232
232
-
createQueryKey('getInventory', options)
233
233
-
234
222
/**
235
223
* Returns pet inventories by status.
236
224
* Returns a map of status codes to quantities.
237
225
*/
238
226
export const getInventoryQuery = defineQueryOptions((options?: Options<GetInventoryData>) => ({
239
239
-
key: getInventoryQueryKey(options),
227
227
+
key: createQueryKey('getInventory', options),
240
228
query: async (context) => {
241
229
const { data } = await getInventory({
242
230
...options,
···
281
269
}
282
270
})
283
271
284
284
-
export const getOrderByIdQueryKey = (options: Options<GetOrderByIdData>) =>
285
285
-
createQueryKey('getOrderById', options)
286
286
-
287
272
/**
288
273
* Find purchase order by ID.
289
274
* For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions.
290
275
*/
291
276
export const getOrderByIdQuery = defineQueryOptions((options: Options<GetOrderByIdData>) => ({
292
292
-
key: getOrderByIdQueryKey(options),
277
277
+
key: createQueryKey('getOrderById', options),
293
278
query: async (context) => {
294
279
const { data } = await getOrderById({
295
280
...options,
···
338
323
}
339
324
})
340
325
341
341
-
export const loginUserQueryKey = (options?: Options<LoginUserData>) =>
342
342
-
createQueryKey('loginUser', options)
343
343
-
344
326
/**
345
327
* Logs user into the system.
346
328
* Log into the system.
347
329
*/
348
330
export const loginUserQuery = defineQueryOptions((options?: Options<LoginUserData>) => ({
349
349
-
key: loginUserQueryKey(options),
331
331
+
key: createQueryKey('loginUser', options),
350
332
query: async (context) => {
351
333
const { data } = await loginUser({
352
334
...options,
···
357
339
}
358
340
}))
359
341
360
360
-
export const logoutUserQueryKey = (options?: Options<LogoutUserData>) =>
361
361
-
createQueryKey('logoutUser', options)
362
362
-
363
342
/**
364
343
* Logs out current logged in user session.
365
344
* Log user out of the system.
366
345
*/
367
346
export const logoutUserQuery = defineQueryOptions((options?: Options<LogoutUserData>) => ({
368
368
-
key: logoutUserQueryKey(options),
347
347
+
key: createQueryKey('logoutUser', options),
369
348
query: async (context) => {
370
349
const { data } = await logoutUser({
371
350
...options,
···
393
372
}
394
373
})
395
374
396
396
-
export const getUserByNameQueryKey = (options: Options<GetUserByNameData>) =>
397
397
-
createQueryKey('getUserByName', options)
398
398
-
399
375
/**
400
376
* Get user by user name.
401
377
* Get user detail based on username.
402
378
*/
403
379
export const getUserByNameQuery = defineQueryOptions((options: Options<GetUserByNameData>) => ({
404
404
-
key: getUserByNameQueryKey(options),
380
380
+
key: createQueryKey('getUserByName', options),
405
381
query: async (context) => {
406
382
const { data } = await getUserByName({
407
383
...options,
+12
-16
examples/openapi-ts-pinia-colada/src/views/PiniaColadaExample.vue
···
4
4
import { PiniaColadaDevtools } from '@pinia/colada-devtools'
5
5
import { createClient } from '@/client/client'
6
6
import { PetSchema } from '@/client/schemas.gen'
7
7
-
import {
8
8
-
addPetMutation,
9
9
-
getPetByIdQuery,
10
10
-
getPetByIdQueryKey,
11
11
-
updatePetMutation
12
12
-
} from '@/client/@pinia/colada.gen'
7
7
+
import { addPetMutation, getPetByIdQuery, updatePetMutation } from '@/client/@pinia/colada.gen'
13
8
import { useQuery, useMutation, useQueryCache } from '@pinia/colada'
14
9
import { ref, watch } from 'vue'
15
10
···
42
37
const petInput = ref({ name: '', category: '' })
43
38
44
39
const { data: pet, error } = useQuery(() => ({
45
45
-
...getPetByIdQuery(petQueryOptions()),
40
40
+
...getPetByIdQuery({
41
41
+
path: {
42
42
+
petId: petId.value as number
43
43
+
}
44
44
+
}),
46
45
enabled: petId.value !== undefined
47
46
}))
48
47
const { mutateAsync: createPet } = useMutation(addPetMutation())
···
50
49
51
50
const queryCache = useQueryCache()
52
51
async function invalidateCurrentPet() {
53
53
-
const key = getPetByIdQueryKey(petQueryOptions())
52
52
+
const { key } = getPetByIdQuery({
53
53
+
path: {
54
54
+
petId: petId.value as number
55
55
+
}
56
56
+
})
54
57
await queryCache.invalidateQueries({ key, exact: true })
55
58
}
56
59
···
87
90
await updatePetIdAndInvalidate(result.id)
88
91
}
89
92
90
90
-
function petQueryOptions() {
91
91
-
return {
92
92
-
client: localClient,
93
93
-
path: { petId: petId.value as number }
94
94
-
}
95
95
-
}
96
96
-
97
93
function randomInt(min: number, max: number) {
98
94
return Math.floor(Math.random() * (max - min + 1) + min)
99
95
}
···
122
118
}
123
119
124
120
watch(error, (error) => {
125
125
-
console.log(error)
121
121
+
console.error(error)
126
122
})
127
123
</script>
128
124