-
Notifications
You must be signed in to change notification settings - Fork 0
RFC: Object Identification #1
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 1 commit
46437e9
6b6c02c
66a382b
058a4c6
0b43872
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 | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,89 @@ | ||||||
| # RFC: Object Identification | ||||||
|
|
||||||
| **Proposed by:** [Lenz Weber-Tronic](https://github.com/phryneas) - Apollo | ||||||
|
|
||||||
| ## Problem statement | ||||||
|
|
||||||
| Currently, there is no way for clients to know if an object is can be uniquely identified. This makes it hard for clients to implement caching strategies that rely on object identity for normalization, or for AI agents that need to communicate with other systems, referencing objects returned from a GraphQL API. | ||||||
|
|
||||||
| This is in part solved by patterns like [Global Object Identification](https://graphql.org/learn/global-object-identification/), but this is nothing clients can generally rely on, since there is no guarantee that a server actually follows this pattern or just accidentally overlaps with it, without actually fully implementing it. | ||||||
|
|
||||||
| Also, the Global Object Identification pattern is not enough for the use case of a Client without schema knowledge - such a client couldn't inject a selection for `id` into all object selections (as they usually do with `__typename`), since it doesn't know which objects actually have an `id` field and the resulting query might be invalid. | ||||||
|
|
||||||
| ## Proposal | ||||||
|
|
||||||
| ### Introduction of an `__id` introspection field | ||||||
|
|
||||||
| This proposal introduces a new introspection field `__id`, which can be queried on any object, interface or union type. | ||||||
| The field is of type `ID` and for each individual type, the field must either always return a non-null value or always return null. | ||||||
| It might never be `null` for some objects of a type while being `ID!` for other objects of the same type. | ||||||
|
||||||
| If an `__id` field returns a non-null value for a type, this value must be guaranteed to uniquely identify the object when combined with the value of the `__typename` field. | ||||||
|
|
||||||
| This would allow clients without schema knowledge to query for `__id` on selection set and use the returned value for caching or referencing the object in other systems, if it is not `null`. | ||||||
| As a result, this would remove the need for manual configuration like Apollo Client's [`keyFields` type policies](https://www.apollographql.com/docs/react/caching/cache-configuration#customizing-cache-ids) or urqls's [Custom Keys](https://nearform.com/open-source/urql/docs/graphcache/normalized-caching/#custom-keys-and-non-keyable-entities), which are currently needed to tell the client which fields to use for identifying an object. | ||||||
| These configurations are often a source of bugs, since they can be forgotten or misconfigured, or simply may not keep up with an evolving schema. | ||||||
|
|
||||||
| ### Intoduction of an `__Entity` interface | ||||||
|
|
||||||
| In addition to the `__id` field, this proposal also introduces a new introspection interface `__Entity`, which is defined as follows: | ||||||
|
|
||||||
| ```graphql | ||||||
| interface __Entity { | ||||||
| __id: ID! | ||||||
|
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.
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. If it's an entity, it's identifiable. This goes hand in hand with that requirement of "for a type, 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. In the world of |
||||||
| } | ||||||
| ``` | ||||||
|
|
||||||
| This interface could be used by clients with schema knowledge (such as Apollo Kotlin or Apollo iOS) at build time to decide if a certain type can be uniquely identified (and thus, stored in a normalized way) or not. | ||||||
|
|
||||||
| This interface may implicitly added to objects that implement a way to resolve the `__id` field to a non-null value, depending on the server implementation. | ||||||
phryneas marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| Alternatively, implementers might also choose to explicitly add the interface to types that can be uniquely identified. | ||||||
|
|
||||||
| ### Feature detection | ||||||
|
||||||
| ### Feature detection | |
| ### Presence of globally identifiable types in the schema |
Uh oh!
There was an error while loading. Please reload this page.