Skip to content

Commit 7f446ab

Browse files
committed
Use deterministic order for type policy keyFields and field policy keyArgs
1 parent f5ad133 commit 7f446ab

File tree

2 files changed

+3
-3
lines changed
  • normalized-cache-apollo-compiler-plugin/src/main/kotlin/com/apollographql/cache/apollocompilerplugin/internal
  • normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/api

2 files changed

+3
-3
lines changed

normalized-cache-apollo-compiler-plugin/src/main/kotlin/com/apollographql/cache/apollocompilerplugin/internal/CacheSchemaCodeGenerator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ internal class CacheSchemaCodeGenerator(
147147
withIndent {
148148
addStatement("keyFields = setOf(")
149149
withIndent {
150-
typePolicy.keyFields.forEach { keyField ->
150+
typePolicy.keyFields.sorted().forEach { keyField ->
151151
addStatement("%S, ", keyField)
152152
}
153153
}

normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/api/CacheResolver.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,10 @@ fun FieldPolicyCacheResolver(
261261
) = object : CacheResolver {
262262
override fun resolveField(context: ResolverContext): Any? {
263263
val keyArgs = context.field.argumentValues(context.variables) { it.definition.isKey }
264-
val keyArgsValues = keyArgs.values
265-
if (keyArgsValues.isEmpty()) {
264+
if (keyArgs.values.isEmpty()) {
266265
return DefaultCacheResolver.resolveField(context)
267266
}
267+
val keyArgsValues = keyArgs.entries.sortedBy { it.key }.map { it.value }
268268
var type = context.field.type
269269
if (type is CompiledNotNullType) {
270270
type = type.ofType

0 commit comments

Comments
 (0)