Skip to content

Instantly share code, notes, and snippets.

@Lavanyagaur22
Created April 6, 2019 08:13
Show Gist options
  • Save Lavanyagaur22/a857cf5927ae12b2c2a7f2938c8d7b19 to your computer and use it in GitHub Desktop.
Save Lavanyagaur22/a857cf5927ae12b2c2a7f2938c8d7b19 to your computer and use it in GitHub Desktop.
private fun cacheResolver(): CacheKeyResolver {
return object : CacheKeyResolver() {
override fun fromFieldRecordSet(field: Field, recordSet: MutableMap<String, Any>): CacheKey {
Log.e("UtilClass", "fromFieldRecordSet ${(recordSet["id"] as String)}")
if (recordSet.containsKey("id")) {
val typeNameAndIDKey = recordSet["__typename"].toString() + "." + recordSet["id"]
return CacheKey.from(typeNameAndIDKey)
}
return CacheKey.NO_KEY
}
// Use this resolver to customize the key for fields with variables: eg entry(repoFullName: $repoFullName).
// This is useful if you want to make query to be able to resolved, even if it has never been run before.
override fun fromFieldArguments(field: Field, variables: Operation.Variables): CacheKey {
Log.e("UtilClass", "fromFieldArguments $variables")
return CacheKey.NO_KEY
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment