Skip to content

Allow to specify a delegate resolver when using CacheControlCacheResolver #56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,10 @@ public final class com/apollographql/cache/normalized/api/ApolloCacheHeaders {
}

public final class com/apollographql/cache/normalized/api/CacheControlCacheResolver : com/apollographql/cache/normalized/api/CacheResolver {
public fun <init> ()V
public fun <init> (Lcom/apollographql/cache/normalized/api/MaxAgeProvider;)V
public fun <init> (Lcom/apollographql/cache/normalized/api/CacheResolver;)V
public synthetic fun <init> (Lcom/apollographql/cache/normalized/api/CacheResolver;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Lcom/apollographql/cache/normalized/api/MaxAgeProvider;Lcom/apollographql/cache/normalized/api/CacheResolver;)V
public synthetic fun <init> (Lcom/apollographql/cache/normalized/api/MaxAgeProvider;Lcom/apollographql/cache/normalized/api/CacheResolver;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun resolveField (Lcom/apollographql/cache/normalized/api/ResolverContext;)Ljava/lang/Object;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ abstract interface com.apollographql.cache.normalized/ApolloStore { // com.apoll
}
}
final class com.apollographql.cache.normalized.api/CacheControlCacheResolver : com.apollographql.cache.normalized.api/CacheResolver { // com.apollographql.cache.normalized.api/CacheControlCacheResolver|null[0]
constructor <init>() // com.apollographql.cache.normalized.api/CacheControlCacheResolver.<init>|<init>(){}[0]
constructor <init>(com.apollographql.cache.normalized.api/MaxAgeProvider) // com.apollographql.cache.normalized.api/CacheControlCacheResolver.<init>|<init>(com.apollographql.cache.normalized.api.MaxAgeProvider){}[0]
constructor <init>(com.apollographql.cache.normalized.api/CacheResolver = ...) // com.apollographql.cache.normalized.api/CacheControlCacheResolver.<init>|<init>(com.apollographql.cache.normalized.api.CacheResolver){}[0]
constructor <init>(com.apollographql.cache.normalized.api/MaxAgeProvider, com.apollographql.cache.normalized.api/CacheResolver = ...) // com.apollographql.cache.normalized.api/CacheControlCacheResolver.<init>|<init>(com.apollographql.cache.normalized.api.MaxAgeProvider;com.apollographql.cache.normalized.api.CacheResolver){}[0]
final fun resolveField(com.apollographql.cache.normalized.api/ResolverContext): kotlin/Any? // com.apollographql.cache.normalized.api/CacheControlCacheResolver.resolveField|resolveField(com.apollographql.cache.normalized.api.ResolverContext){}[0]
}
final class com.apollographql.cache.normalized.api/CacheHeaders { // com.apollographql.cache.normalized.api/CacheHeaders|null[0]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,26 @@ object DefaultCacheResolver : CacheResolver {
*
* A maximum staleness can be configured via the [ApolloCacheHeaders.MAX_STALE] cache header.
*
* @param maxAgeProvider the provider for the max age of fields
* @param delegateResolver the resolver to delegate to for non-stale fields, by default [FieldPolicyCacheResolver]
*
* @see MutableExecutionOptions.storeReceiveDate
* @see MutableExecutionOptions.storeExpirationDate
* @see MutableExecutionOptions.maxStale
*/
class CacheControlCacheResolver(
private val maxAgeProvider: MaxAgeProvider,
private val delegateResolver: CacheResolver = FieldPolicyCacheResolver,
) : CacheResolver {
/**
* Creates a new [CacheControlCacheResolver] with no max ages. Use this constructor if you want to consider only the expiration dates.
*/
constructor() : this(maxAgeProvider = GlobalMaxAgeProvider(Duration.INFINITE))
constructor(
delegateResolver: CacheResolver = FieldPolicyCacheResolver,
) : this(
maxAgeProvider = GlobalMaxAgeProvider(Duration.INFINITE),
delegateResolver = delegateResolver,
)

override fun resolveField(context: ResolverContext): Any? {
var isStale = false
Expand Down Expand Up @@ -198,7 +207,7 @@ class CacheControlCacheResolver(
}
}

val value = FieldPolicyCacheResolver.resolveField(context)
val value = delegateResolver.resolveField(context)
return if (isStale) {
ResolvedValue(
value = value,
Expand Down