@@ -63,14 +63,12 @@ export type UseResponseCacheParameter<PluginContext extends Record<string, any>
63
63
*/
64
64
ttl ?: number ;
65
65
/**
66
- * Overwrite the ttl for query operations whose execution result contains a specific object type.
67
- * Useful if the occurrence of a object time in the execution result should reduce or increase the TTL of the query operation.
68
- * The TTL per type is always favored over the global TTL.
66
+ * @deprecated Use `ttlPerSchemaCoordinate` instead.
69
67
*/
70
68
ttlPerType ?: Record < string , number > ;
71
69
/**
72
- * Overwrite the ttl for query operations whose selection contains a specific schema coordinate (e.g. Query.users).
73
- * Useful if the selection of a specific field should reduce the TTL of the query operation.
70
+ * Overwrite the ttl for query operations whose selection contains a specific schema coordinate (e.g. Query or Query .users).
71
+ * Useful if the selection of an a object type or a specific field should reduce or increase the TTL of the query operation.
74
72
*
75
73
* The default value is `{}` and it will be merged with a `{ 'Query.__schema': 0 }` object.
76
74
* In the unusual case where you actually want to cache introspection query operations,
@@ -290,7 +288,7 @@ export function useResponseCache<PluginContext extends Record<string, any> = {}>
290
288
session,
291
289
enabled,
292
290
ignoredTypes = [ ] ,
293
- ttlPerType = { } ,
291
+ ttlPerType,
294
292
ttlPerSchemaCoordinate = { } ,
295
293
scopePerSchemaCoordinate = { } ,
296
294
idFields = [ 'id' ] ,
@@ -310,6 +308,12 @@ export function useResponseCache<PluginContext extends Record<string, any> = {}>
310
308
311
309
// never cache Introspections
312
310
ttlPerSchemaCoordinate = { 'Query.__schema' : 0 , ...ttlPerSchemaCoordinate } ;
311
+ if ( ttlPerType ) {
312
+ for ( const [ typeName , ttl ] of Object . entries ( ttlPerType ) ) {
313
+ ttlPerSchemaCoordinate [ typeName ] = ttl ;
314
+ }
315
+ }
316
+
313
317
const documentMetadataOptions = {
314
318
queries : { invalidateViaMutation, ttlPerSchemaCoordinate } ,
315
319
mutations : { invalidateViaMutation } , // remove ttlPerSchemaCoordinate for mutations to skip TTL calculation
@@ -347,7 +351,7 @@ export function useResponseCache<PluginContext extends Record<string, any> = {}>
347
351
) as unknown as CacheControlDirective [ ] | undefined ;
348
352
cacheControlAnnotations ?. forEach ( cacheControl => {
349
353
if ( cacheControl . maxAge != null ) {
350
- ttlPerType [ type . name ] = cacheControl . maxAge * 1000 ;
354
+ ttlPerSchemaCoordinate [ type . name ] = cacheControl . maxAge * 1000 ;
351
355
}
352
356
if ( cacheControl . scope ) {
353
357
scopePerSchemaCoordinate [ type . name ] = cacheControl . scope ;
@@ -450,8 +454,8 @@ export function useResponseCache<PluginContext extends Record<string, any> = {}>
450
454
}
451
455
452
456
types . add ( typename ) ;
453
- if ( typename in ttlPerType ) {
454
- const maybeTtl = ttlPerType [ typename ] as unknown ;
457
+ if ( typename in ttlPerSchemaCoordinate ) {
458
+ const maybeTtl = ttlPerSchemaCoordinate [ typename ] as unknown ;
455
459
currentTtl = calculateTtl ( maybeTtl , currentTtl ) ;
456
460
}
457
461
if ( entityId != null ) {
@@ -462,8 +466,8 @@ export function useResponseCache<PluginContext extends Record<string, any> = {}>
462
466
if ( fieldData == null || ( Array . isArray ( fieldData ) && fieldData . length === 0 ) ) {
463
467
const inferredTypes = typePerSchemaCoordinateMap . get ( `${ typename } .${ fieldName } ` ) ;
464
468
inferredTypes ?. forEach ( inferredType => {
465
- if ( inferredType in ttlPerType ) {
466
- const maybeTtl = ttlPerType [ inferredType ] as unknown ;
469
+ if ( inferredType in ttlPerSchemaCoordinate ) {
470
+ const maybeTtl = ttlPerSchemaCoordinate [ inferredType ] as unknown ;
467
471
currentTtl = calculateTtl ( maybeTtl , currentTtl ) ;
468
472
}
469
473
identifier . set ( inferredType , { typename : inferredType } ) ;
0 commit comments