-
Notifications
You must be signed in to change notification settings - Fork 5
Use deterministic order for type policy keyFields and field policy keyArgs #243
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,9 +7,10 @@ import com.apollographql.apollo.ast.GQLTypeDefinition | |
| import com.apollographql.apollo.ast.Schema | ||
| import com.apollographql.apollo.ast.Schema.Companion.TYPE_POLICY | ||
| import com.apollographql.apollo.ast.SourceAwareException | ||
| import java.util.SortedSet | ||
|
|
||
| internal data class TypePolicy( | ||
| val keyFields: Set<String>, | ||
| val keyFields: SortedSet<String>, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can just use Note: the equivalent |
||
| val embeddedFields: Set<String>, | ||
| ) | ||
|
|
||
|
|
@@ -83,7 +84,7 @@ private fun Schema.validateAndComputeTypePolicy( | |
|
|
||
| private fun GQLDirective.toTypePolicy(): TypePolicy { | ||
| return TypePolicy( | ||
| keyFields = extractFields("keyFields"), | ||
| keyFields = extractFields("keyFields").toSortedSet(), | ||
| embeddedFields = extractFields("embeddedFields") | ||
| ) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -261,10 +261,10 @@ fun FieldPolicyCacheResolver( | |
| ) = object : CacheResolver { | ||
| override fun resolveField(context: ResolverContext): Any? { | ||
| val keyArgs = context.field.argumentValues(context.variables) { it.definition.isKey } | ||
| val keyArgsValues = keyArgs.values | ||
| if (keyArgsValues.isEmpty()) { | ||
| if (keyArgs.values.isEmpty()) { | ||
| return DefaultCacheResolver.resolveField(context) | ||
| } | ||
| val keyArgsValues = keyArgs.entries.sortedBy { it.key }.map { it.value } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this works only if the key arguments of a field have the same names as the key fields of the type. So for example: extend type User @typePolicy(keyFields: "firstName lastName")
extend type Query @fieldPolicy(forField: "user", keyArgs: "firstName lastName"){
user(firstName: "john", lastName: "smith") {
firstName
lastName
}
}
But extend type User @typePolicy(keyFields: "firstName lastName")
extend type Query @fieldPolicy(forField: "user", keyArgs: "a b"){
user(b: "john", a: "smith") {
firstName
lastName
}
}
In the end I think it would make sense to use the same orders as defined in But this soon will be possible, because for the key args, I intend to not use |
||
| var type = context.field.type | ||
| if (type is CompiledNotNullType) { | ||
| type = type.ofType | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we use a
ListI think it'd make more sense to keep the user-defined order set in@typePolicy.