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

GraphQL · Const

scalar

A GraphQL scalar is a leaf type that resolves to one concrete value and cannot have nested selections. GraphQL includes Int, Float, String, Boolean, and ID, and services can define custom scalars.

How it works

A scalar is a leaf type that resolves to one concrete value, so clients select it without a nested selection set. GraphQL provides Int, Float, String, Boolean, and ID, while services may add custom scalars for domain-specific values.

Syntax

scalar Name

Returns

A single scalar value at a query leaf.

Key points

  • Scalars terminate field traversal by supplying the concrete values returned to clients.
  • Int represents signed 32-bit whole numbers.
  • Float represents signed double-precision numeric values.
  • String represents UTF-8 text.
  • Boolean represents a true-or-false value.
  • ID communicates identifier intent and is commonly used for refetching objects or cache keys.
  • Implementations commonly support custom scalars for additional domain-specific leaf types.

Common mistakes

  • Do not add a nested selection set beneath a scalar field.
  • ID may serialize like String, but its type communicates identifier semantics rather than human-readable text.

Example: Selecting scalar fields

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

The query selects scalar leaf fields from an object returned by the API.

When to use it

Model primitive fields

Choose Int, Float, String, Boolean, or ID when a field returns a standard primitive value.

Represent identifiers

Use ID for values that identify objects, support refetching, or act as cache keys.

Add domain-specific values

Define a custom scalar when a service needs a domain-specific leaf value beyond the built-ins.

Interview questions

QWhat is a GraphQL scalar?

Scalars represent the leaf values of a GraphQL query and resolve to one concrete value. Unlike object types, they do not expose fields for further selection.

Follow-up: Why can a query end at a scalar? Because scalar resolution produces the final value, so there is no subordinate field structure to traverse.

QWhich scalar types does GraphQL provide?

The built-in scalars are Int, Float, String, Boolean, and ID. Int is a signed 32-bit integer, Float is double precision, String is UTF-8 text, Boolean is true or false, and ID is intended for unique identifiers.

Follow-up: When should ID be preferred over String? Use ID when the value identifies an object or is used as a cache key, even though it is serialized like a String.

QCan GraphQL services define custom scalars?

A service can define custom scalar types in addition to the built-in scalars. Custom scalars allow the schema to represent domain-specific leaf values.

Follow-up: How should a custom scalar differ from an object type? It should represent one leaf value rather than a value with selectable fields.

  • Object types
  • Enum types
  • Input Object types
  • Non-Null
  • List types

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