Caching and refetching
A client stores an object's identifier and later uses it to read or refresh the same object.
GraphQL · Const
GraphQL's ID scalar is used for object identifiers. The global object identification convention makes IDs reusable for caching, refetching, and fetching objects through a standard node field.
GraphQL's ID scalar represents a unique identifier for an object. It serializes as a string, but servers may accept either a string or an integer as input; clients should treat the value as opaque rather than depending on its internal format.
scalar ID| Name | Type | Description |
|---|---|---|
id | ID! | The object's identifier; for the standardized node lookup, this is the sole required argument and has type ID!. |
The ID scalar is returned as a string. In the global object identification convention, the node field returns the Node interface.
node lookup accepts exactly one required ID argument.Node interface has one field named id, and its type is non-null ID.Node interface.query GetUser($id: ID!) {
user(id: $id) {
id
name
}
}This query passes an identifier variable to a field argument typed as ID and requests the object's ID along with another field.
A client stores an object's identifier and later uses it to read or refresh the same object.
A schema offers a uniform way to retrieve different object types by one identifier.
A query variable identifies the object passed to a field argument.
The ID scalar is used for object identifiers. Although it is represented as a string in responses, GraphQL input may accept either a string or an integer, depending on the server's coercion rules.
Follow-up: Why should a client avoid parsing an ID? The identifier is intended to be reused as an opaque value for caching, refetching, or requesting the object again.
A globally unique ID lets a client identify an object consistently and reuse that value for caching and refetching. The global-identification convention exposes it through an object's id field.
Follow-up: What additional root field does that convention require? A node field that accepts one non-null ID argument and returns the Node interface.
The global-identification convention requires a Node interface with exactly one field, id, returning non-null ID. That ID should uniquely identify the object and allow the server to fetch it again.
Follow-up: How does a client retrieve a node by ID? It queries the root node field with the identifier and then selects fields through the returned interface.
Nodenodeglobal object identificationcachingrefetching__type