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

GraphQL · Const

GraphQLID

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.

How it works

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.

Syntax

id: ID!

Parameters

NameTypeDescription
idID!A unique object identifier supplied to the field; it is commonly declared as a non-null ID argument.

Returns

ID, commonly declared as ID! when the identifier is required.

Key points

  • ID is one of GraphQL's five built-in scalar types, alongside Int, Float, String, and Boolean.
  • Use ID for values that identify objects across requests or that clients may retain as cache keys.
  • At the response boundary, an ID uses string serialization rather than a separate numeric wire representation.
  • ID requires no custom scalar definition because GraphQL implementations provide it as a standard scalar.
  • An ID field is a leaf selection and cannot have nested subfields.

Common mistakes

  • ID does not preserve a distinct wire format from String; its semantic purpose is to identify an opaque value.
  • Do not design an ID field as a display label or expose it as a value users are expected to interpret.

Example: Use ID for an object identifier

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.

When to use it

Object lookup

A query field retrieves one object by its opaque identifier.

Cache keys

A client stores identifiers to associate normalized records across responses.

Opaque identity

A schema exposes a stable identifier that clients can reuse without interpreting its format.

Interview questions

QWhat is the purpose of GraphQL's ID scalar?

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.

QWhat does ID! mean in a schema?

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.

QWhy is ID useful to GraphQL clients?

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.

  • ID
  • String
  • Scalar types
  • Global Object Identification
  • Node
  • id

Source: Schemas and Types - GraphQL. Checked 2026-10-15.