Object lookup
A query field retrieves one object by its opaque identifier.
GraphQL · Const
GraphQLID corresponds to GraphQL’s built-in ID scalar. It represents an opaque unique identifier, commonly used to refetch objects or as a cache key, and is serialized like a string.
GraphQLID is represented in GraphQL schema notation by the built-in ID scalar. It is intended for unique, opaque identifiers used to retrieve objects or support caching; although it serializes like a string, it signals that people should not treat the value as human-readable.
id: ID!| Name | Type | Description |
|---|---|---|
id | ID! | A unique object identifier supplied to the field; it is commonly declared as a non-null ID argument. |
ID, commonly declared as ID! when the identifier is required.
type Query {
user(id: ID!): User
}
type User {
id: ID!
name: String!
}This schema uses ID for an opaque user identifier and makes both the lookup argument and returned identifier required.
A query field retrieves one object by its opaque identifier.
A client stores identifiers to associate normalized records across responses.
A schema exposes a stable identifier that clients can reuse without interpreting its format.
ID is a built-in scalar for unique identifiers, commonly used to refetch objects or serve as cache keys. It serializes like String, but its schema meaning says the value is opaque rather than intended for human reading.
Follow-up: Why not use String for every identifier? String lacks the identifier-specific contract, so ID communicates intent to clients and tooling even though both serialize as strings.
A field declared ID! must return a non-null ID, and an argument declared ID! is required in the operation. The exclamation mark applies GraphQL's non-null wrapper to the ID scalar.
Follow-up: What changes when the declaration is ID instead? The value may be null, so callers and resolvers must account for absence.
ID is useful for object lookup and caching because it represents an identifier whose format clients should treat as opaque. A client can store and reuse it without relying on whether the underlying value is numeric or textual.
Follow-up: How can a schema standardize refetching across object types? It can expose a globally unique ID through a Node interface and a root node field, as described by the Global Object Identification guide.
IDStringScalar typesGlobal Object IdentificationNodeid