@@ -13,6 +13,7 @@ import type {
13
13
InvalidateOptions ,
14
14
InvalidateQueryFilters ,
15
15
MutationKey ,
16
+ MutationObserverOptions ,
16
17
MutationOptions ,
17
18
QueryFunction ,
18
19
QueryKey ,
@@ -302,7 +303,7 @@ export class QueryClient {
302
303
303
304
setQueryDefaults (
304
305
queryKey : QueryKey ,
305
- options : QueryOptions < any , any , any >
306
+ options : QueryObserverOptions < any , any , any , any >
306
307
) : void {
307
308
const result = this . queryDefaults . find (
308
309
x => hashQueryKey ( queryKey ) === hashQueryKey ( x . queryKey )
@@ -315,15 +316,17 @@ export class QueryClient {
315
316
}
316
317
317
318
getQueryDefaults (
318
- queryKey : QueryKey
319
- ) : QueryOptions < any , any , any > | undefined {
320
- return this . queryDefaults . find ( x => partialMatchKey ( queryKey , x . queryKey ) )
321
- ?. defaultOptions
319
+ queryKey ?: QueryKey
320
+ ) : QueryObserverOptions < any , any , any > | undefined {
321
+ return queryKey
322
+ ? this . queryDefaults . find ( x => partialMatchKey ( queryKey , x . queryKey ) )
323
+ ?. defaultOptions
324
+ : undefined
322
325
}
323
326
324
327
setMutationDefaults (
325
328
mutationKey : MutationKey ,
326
- options : MutationOptions < any , any , any , any >
329
+ options : MutationObserverOptions < any , any , any , any >
327
330
) : void {
328
331
const result = this . mutationDefaults . find (
329
332
x => hashQueryKey ( mutationKey ) === hashQueryKey ( x . mutationKey )
@@ -336,27 +339,45 @@ export class QueryClient {
336
339
}
337
340
338
341
getMutationDefaults (
339
- mutationKey : MutationKey
340
- ) : MutationOptions < any , any , any , any > | undefined {
341
- return this . mutationDefaults . find ( x =>
342
- partialMatchKey ( mutationKey , x . mutationKey )
343
- ) ?. defaultOptions
342
+ mutationKey ?: MutationKey
343
+ ) : MutationObserverOptions < any , any , any , any > | undefined {
344
+ return mutationKey
345
+ ? this . mutationDefaults . find ( x =>
346
+ partialMatchKey ( mutationKey , x . mutationKey )
347
+ ) ?. defaultOptions
348
+ : undefined
344
349
}
345
350
346
351
defaultQueryOptions < T extends QueryOptions < any , any > > ( options ?: T ) : T {
347
- return { ...this . defaultOptions . queries , ...options } as T
352
+ if ( options ?. _defaulted ) {
353
+ return options
354
+ }
355
+ return {
356
+ ...this . defaultOptions . queries ,
357
+ ...this . getQueryDefaults ( options ?. queryKey ) ,
358
+ ...options ,
359
+ _defaulted : true ,
360
+ } as T
348
361
}
349
362
350
363
defaultQueryObserverOptions < T extends QueryObserverOptions < any , any > > (
351
364
options ?: T
352
365
) : T {
353
- return { ... this . defaultOptions . queries , ... options } as T
366
+ return this . defaultQueryOptions ( options )
354
367
}
355
368
356
369
defaultMutationOptions < T extends MutationOptions < any , any , any , any > > (
357
370
options ?: T
358
371
) : T {
359
- return { ...this . defaultOptions . mutations , ...options } as T
372
+ if ( options ?. _defaulted ) {
373
+ return options
374
+ }
375
+ return {
376
+ ...this . defaultOptions . mutations ,
377
+ ...this . getMutationDefaults ( options ?. mutationKey ) ,
378
+ ...options ,
379
+ _defaulted : true ,
380
+ } as T
360
381
}
361
382
362
383
clear ( ) : void {
0 commit comments