Scalar Types
Scalar types represent leaf values in a GraphQL response. GraphQL provides five built-in scalar types:
Int— a signed 32-bit integer.Float— a signed double-precision floating-point value.String— a UTF-8 character sequence.Boolean—trueorfalse.ID— an identifier intended to be serialized as a string.
Example:
type Product {
id: ID!
name: String!
quantity: Int!
price: Float!
available: Boolean!
}
A scalar is a leaf because the client cannot select fields beneath it.
For example:
product {
name
price
}
is valid, but this is not:
product {
price {
value
}
}
because Float has no child fields.
ID versus String
An ID represents an identifier. It is commonly used for database identifiers and resource identifiers. Although GraphQL serializes IDs in a string-compatible way, using ID communicates semantic intent: this value identifies something.
Integer versus Float
Use Int for whole numbers and Float for decimal numbers. Be careful with financial data: a GraphQL Float should not automatically be interpreted as an appropriate representation for exact monetary calculations. Production financial systems often use decimal representations at the application or database layer.
32-bit signed integerDouble-precision floating pointUTF-8 texttrue or falseIdentifier- Scalars are GraphQL leaf values.
- GraphQL provides five built-in scalar types.
- ID communicates identifier semantics.
- Scalar types cannot have nested selections.
Which built-in GraphQL scalar is intended specifically to represent identifiers?