@@ -68,9 +68,7 @@ export type UseResponseCacheParameter<PluginContext extends Record<string, any>
68
68
*/
69
69
ttl ?: number ;
70
70
/**
71
- * Overwrite the ttl for query operations whose execution result contains a specific object type.
72
- * Useful if the occurrence of a object time in the execution result should reduce or increase the TTL of the query operation.
73
- * The TTL per type is always favored over the global TTL.
71
+ * @deprecated Use `ttlPerSchemaCoordinate` instead.
74
72
*/
75
73
ttlPerType ?: Record < string , number > ;
76
74
/**
@@ -308,7 +306,7 @@ export function useResponseCache<PluginContext extends Record<string, any> = {}>
308
306
session,
309
307
enabled,
310
308
ignoredTypes = [ ] ,
311
- ttlPerType = { } ,
309
+ ttlPerType,
312
310
ttlPerSchemaCoordinate = { } ,
313
311
scopePerSchemaCoordinate = { } ,
314
312
idFields = [ 'id' ] ,
@@ -329,6 +327,16 @@ export function useResponseCache<PluginContext extends Record<string, any> = {}>
329
327
330
328
// never cache Introspections
331
329
ttlPerSchemaCoordinate = { 'Query.__schema' : 0 , ...ttlPerSchemaCoordinate } ;
330
+ if ( ttlPerType ) {
331
+ // eslint-disable-next-line no-console
332
+ console . warn (
333
+ '[useResponseCache] `ttlForType` is deprecated. To migrate, merge it with `ttlForSchemaCoordinate` option' ,
334
+ ) ;
335
+ for ( const [ typeName , ttl ] of Object . entries ( ttlPerType ) ) {
336
+ ttlPerSchemaCoordinate [ typeName ] = ttl ;
337
+ }
338
+ }
339
+
332
340
const documentMetadataOptions = {
333
341
queries : { invalidateViaMutation, ttlPerSchemaCoordinate } ,
334
342
mutations : { invalidateViaMutation } , // remove ttlPerSchemaCoordinate for mutations to skip TTL calculation
@@ -366,7 +374,7 @@ export function useResponseCache<PluginContext extends Record<string, any> = {}>
366
374
) as unknown as CacheControlDirective [ ] | undefined ;
367
375
cacheControlAnnotations ?. forEach ( cacheControl => {
368
376
if ( cacheControl . maxAge != null ) {
369
- ttlPerType [ type . name ] = cacheControl . maxAge * 1000 ;
377
+ ttlPerSchemaCoordinate [ type . name ] = cacheControl . maxAge * 1000 ;
370
378
}
371
379
if ( cacheControl . scope ) {
372
380
scopePerSchemaCoordinate [ type . name ] = cacheControl . scope ;
@@ -461,8 +469,8 @@ export function useResponseCache<PluginContext extends Record<string, any> = {}>
461
469
}
462
470
463
471
types . add ( entity . typename ) ;
464
- if ( entity . typename in ttlPerType ) {
465
- const maybeTtl = ttlPerType [ entity . typename ] as unknown ;
472
+ if ( entity . typename in ttlPerSchemaCoordinate ) {
473
+ const maybeTtl = ttlPerSchemaCoordinate [ entity . typename ] as unknown ;
466
474
currentTtl = calculateTtl ( maybeTtl , currentTtl ) ;
467
475
}
468
476
if ( entity . id != null ) {
@@ -473,8 +481,8 @@ export function useResponseCache<PluginContext extends Record<string, any> = {}>
473
481
if ( fieldData == null || ( Array . isArray ( fieldData ) && fieldData . length === 0 ) ) {
474
482
const inferredTypes = typePerSchemaCoordinateMap . get ( `${ entity . typename } .${ fieldName } ` ) ;
475
483
inferredTypes ?. forEach ( inferredType => {
476
- if ( inferredType in ttlPerType ) {
477
- const maybeTtl = ttlPerType [ inferredType ] as unknown ;
484
+ if ( inferredType in ttlPerSchemaCoordinate ) {
485
+ const maybeTtl = ttlPerSchemaCoordinate [ inferredType ] as unknown ;
478
486
currentTtl = calculateTtl ( maybeTtl , currentTtl ) ;
479
487
}
480
488
identifier . set ( inferredType , { typename : inferredType } ) ;
0 commit comments