Use case
Given an endpoint that returns an interface type, it's currently not possible to set a fieldPolicy that will resolve the various implementation types.
interface Node @typePolicy(keyFields: "id") {
id: ID!
}
type Actual implements Node {
id: ID!
name: String
}
type Query @fieldPolicy(forField: "node", keyArgs: "id") {
node(id: ID!): Node # Cache will never find an Actual object before sending a request
}
I'm trying to use the node field to get a variety of types that have most fields in common. However, since those types are cached using their full type name, it isn't possible to retrieve the object from cache using the node field because only the Node interface is known.
Describe the solution you'd like
Inspired by the rejected RFC apollographql/apollo-ios-dev#549, I want to suggest @typePolicy and @fieldPolicy gain a new field named keyScope, with one of the following possible values:
TYPE: The identifier is unique for the type, e.g. an auto-incrementing column from a database table.
SERVICE: The identifier is unique across the current GraphQL Service, e.g. a type name combined with an auto-increnting column.
UNIVERSAL: The identifier is unique across all GraphQL services, e.g. UUIDs generated through RFC 9562. Exact serialization details are unspecified, as long as all UUID information is present. Appending more information is allowed.
TYPE is the default. If the scope is not TYPE, cache keys should not contain the type name but only use the actual id as a cache key (possibly with a constant prefix).
The GraphQL best practice known as Global Object Identification requires that all ids are unique across the service. This is also a required part of the Relay spec.
Use case
Given an endpoint that returns an interface type, it's currently not possible to set a fieldPolicy that will resolve the various implementation types.
I'm trying to use the
nodefield to get a variety of types that have most fields in common. However, since those types are cached using their full type name, it isn't possible to retrieve the object from cache using thenodefield because only the Node interface is known.Describe the solution you'd like
Inspired by the rejected RFC apollographql/apollo-ios-dev#549, I want to suggest
@typePolicyand@fieldPolicygain a new field namedkeyScope, with one of the following possible values:TYPE: The identifier is unique for the type, e.g. an auto-incrementing column from a database table.SERVICE: The identifier is unique across the current GraphQL Service, e.g. a type name combined with an auto-increnting column.UNIVERSAL: The identifier is unique across all GraphQL services, e.g. UUIDs generated through RFC 9562. Exact serialization details are unspecified, as long as all UUID information is present. Appending more information is allowed.TYPEis the default. If the scope is notTYPE, cache keys should not contain the type name but only use the actual id as a cache key (possibly with a constant prefix).The GraphQL best practice known as Global Object Identification requires that all
ids are unique across the service. This is also a required part of the Relay spec.