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

GraphQL · Const

input

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.

How it works

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.

Syntax

id: ID!

Parameters

NameTypeDescription
idID!An identifier value used by the field to locate an object.

Returns

The selected object, or null when the schema permits the field to return no object.

Key points

  • An ID can represent many underlying formats, but GraphQL exposes its serialized result as a string for consistent client handling.
  • String and integer inputs are accepted for an ID when the service can interpret them.
  • The schema declares the identifier's type, allowing GraphQL to validate ID arguments before execution.
  • A client can use an ID argument to ask the API for a particular object.

Example: Fetch an object by ID

query User($id: ID!) {
  user(id: $id) {
    id
    name
  }
}

Pass the identifier as an ID variable to request a specific object.

When to use it

Fetch a single object by identifier

Object retrieval

Use stable identifiers to associate objects across responses

Client caching

Refetch a globally identifiable object

Schema traversal

Interview questions

QWhat is the purpose of GraphQL's ID scalar?

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.

QHow would a schema require an object identifier?

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.

QWhat input values can GraphQL coerce to an ID?

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-Null
  • Node interface
  • Global Object Identification
  • input types
  • field arguments

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