Model primitive fields
Choose Int, Float, String, Boolean, or ID when a field returns a standard primitive value.
GraphQL · Const
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.
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.
scalar NameA single scalar value at a query leaf.
query GetUser($id: ID!) {
user(id: $id) {
id
name
}
}The query selects scalar leaf fields from an object returned by the API.
Choose Int, Float, String, Boolean, or ID when a field returns a standard primitive value.
Use ID for values that identify objects, support refetching, or act as cache keys.
Define a custom scalar when a service needs a domain-specific leaf value beyond the built-ins.
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.
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.
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 typesEnum typesInput Object typesNon-NullList types