FieldPolicyCacheResolver

fun FieldPolicyCacheResolver(fieldPolicies: Map<String, FieldPolicies>, keyScope: CacheKey.Scope = CacheKey.Scope.TYPE): CacheResolver

A cache resolver that uses @fieldPolicy directives to resolve fields and delegates to DefaultCacheResolver otherwise.

Note: using a CacheKey.Scope.TYPE keyScope namespaces the ids with the schema type, which will lead to cache misses for:

  • unions

  • interfaces that have a @typePolicy on subtypes.

If the ids are unique across the whole service, use CacheKey.Scope.SERVICE. Otherwise there is no way to resolve the cache keys automatically for those cases.

Parameters

fieldPolicies

the field policies where to look for key arguments

keyScope

the scope of the computed cache keys. Use CacheKey.Scope.TYPE to namespace the keys by the schema type name, or CacheKey.Scope.SERVICE if the ids are unique across the whole service.