@@ -59,6 +59,11 @@ export const createQueryKeyFunction = ({
59
59
name : 'infinite' ,
60
60
type : tsc . typeReferenceNode ( { typeName : 'boolean' } ) ,
61
61
} ,
62
+ {
63
+ isRequired : false ,
64
+ name : 'tags' ,
65
+ type : tsc . typeReferenceNode ( { typeName : 'ReadonlyArray<string>' } ) ,
66
+ } ,
62
67
] ,
63
68
returnType : tsc . typeTupleNode ( {
64
69
types : [ returnType ] ,
@@ -100,6 +105,22 @@ export const createQueryKeyFunction = ({
100
105
] ,
101
106
} ) ,
102
107
} ) ,
108
+ tsc . ifStatement ( {
109
+ expression : tsc . identifier ( { text : 'tags' } ) ,
110
+ thenStatement : tsc . block ( {
111
+ statements : [
112
+ tsc . expressionToStatement ( {
113
+ expression : tsc . binaryExpression ( {
114
+ left : tsc . propertyAccessExpression ( {
115
+ expression : 'params' ,
116
+ name : 'tags' ,
117
+ } ) ,
118
+ right : tsc . identifier ( { text : 'tags' } ) ,
119
+ } ) ,
120
+ } ) ,
121
+ ] ,
122
+ } ) ,
123
+ } ) ,
103
124
tsc . ifStatement ( {
104
125
expression : tsc . propertyAccessExpression ( {
105
126
expression : optionsIdentifier ,
@@ -218,10 +239,12 @@ export const createQueryKeyFunction = ({
218
239
const createQueryKeyLiteral = ( {
219
240
id,
220
241
isInfinite,
242
+ operation,
221
243
plugin,
222
244
} : {
223
245
id : string ;
224
246
isInfinite ?: boolean ;
247
+ operation : IR . OperationObject ;
225
248
plugin : PluginInstance ;
226
249
} ) => {
227
250
const file = plugin . context . file ( { id : plugin . name } ) ! ;
@@ -231,12 +254,23 @@ const createQueryKeyLiteral = ({
231
254
case : plugin . config . case ,
232
255
namespace : 'value' ,
233
256
} ) ;
257
+
258
+ const tagsExpression =
259
+ operation . tags && operation . tags . length > 0
260
+ ? tsc . arrayLiteralExpression ( {
261
+ elements : operation . tags . map ( ( tag ) =>
262
+ tsc . stringLiteral ( { text : tag } ) ,
263
+ ) ,
264
+ } )
265
+ : undefined ;
266
+
234
267
const createQueryKeyCallExpression = tsc . callExpression ( {
235
268
functionName : identifierCreateQueryKey . name || '' ,
236
269
parameters : [
237
270
tsc . ots . string ( id ) ,
238
271
'options' ,
239
- isInfinite ? tsc . ots . boolean ( true ) : undefined ,
272
+ tsc . ots . boolean ( ! ! isInfinite ) ,
273
+ tagsExpression ,
240
274
] ,
241
275
} ) ;
242
276
return createQueryKeyCallExpression ;
@@ -259,6 +293,13 @@ export const createQueryKeyType = ({ plugin }: { plugin: PluginInstance }) => {
259
293
keyword : 'boolean' ,
260
294
} ) ,
261
295
} ,
296
+ {
297
+ isRequired : false ,
298
+ name : 'tags' ,
299
+ type : tsc . typeReferenceNode ( {
300
+ typeName : 'ReadonlyArray<string>' ,
301
+ } ) ,
302
+ } ,
262
303
] ;
263
304
264
305
const queryKeyType = tsc . typeAliasDeclaration ( {
@@ -337,6 +378,7 @@ export const queryKeyStatement = ({
337
378
statements : createQueryKeyLiteral ( {
338
379
id : operation . id ,
339
380
isInfinite,
381
+ operation,
340
382
plugin,
341
383
} ) ,
342
384
} ) ,
0 commit comments