Fetch a single object by identifier
Object retrieval
GraphQL · Const
GraphQL's ID scalar represents an object identifier and is commonly used in an id field argument. It supports service-defined identifier formats while presenting serialized IDs consistently as strings.
The GraphQL ID scalar represents an identifier and is commonly used as an argument for fetching an object. A server may use different underlying formats, while clients treat the serialized value consistently as a string; IDs can be supplied as strings or integers, but not floating-point values.
id: ID!| Name | Type | Description |
|---|---|---|
id | ID! | An identifier value used by the field to locate an object. |
The selected object, or null when the schema permits the field to return no object.
query User($id: ID!) {
user(id: $id) {
id
name
}
}Pass the identifier as an ID variable to request a specific object.
Object retrieval
Client caching
Schema traversal
The ID scalar is intended for identifying objects rather than numeric computation. GraphQL serializes IDs as strings so clients can handle identifiers consistently across formats.
Follow-up: Can an ID variable contain an integer? Yes. GraphQL accepts string or integer input for an ID and coerces it according to the service's identifier format.
A field argument that identifies an object can be declared with the ID type, often as a non-null value such as id: ID!. The service decides how that identifier maps to its underlying data.
Follow-up: Why use ID! instead of ID? The non-null marker requires callers to provide an identifier, preventing an absent ID from reaching field resolution.
Clients may provide an ID as either a string or an integer input. A floating-point input is invalid, and the server serializes the resulting ID as a string.
Follow-up: Does GraphQL require IDs to be numeric? No. The service can use formats such as opaque strings, encoded values, or numbers.
Non-NullNode interfaceGlobal Object Identificationinput typesfield arguments