Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

GraphQL · Const

type

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.

How it works

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.

Syntax

scalar ID

Parameters

NameTypeDescription
idID!The object's identifier; for the standardized node lookup, this is the sole required argument and has type ID!.

Returns

The ID scalar is returned as a string. In the global object identification convention, the node field returns the Node interface.

Key points

  • Clients can retain an object's ID and use it again when caching or refetching that object.
  • Under the global-identification convention, the root node lookup accepts exactly one required ID argument.
  • A conforming Node interface has one field named id, and its type is non-null ID.
  • The standardized root lookup returns objects through the Node interface.

Common mistakes

  • An ID is suitable for caching and refetching, but its meaning and format should not be inferred by the client.

Example: Using an ID variable

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.

When to use it

Caching and refetching

A client stores an object's identifier and later uses it to read or refresh the same object.

Global object lookup

A schema offers a uniform way to retrieve different object types by one identifier.

Object-specific queries

A query variable identifies the object passed to a field argument.

Interview questions

QWhat is the purpose of GraphQL's ID scalar?

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.

QHow are IDs used in GraphQL client caching?

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.

QWhat does the GraphQL global object identification convention require?

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.

  • Node
  • node
  • global object identification
  • caching
  • refetching
  • __type

Source: Global Object Identification. Checked 2026-10-15.