0
0
GraphQLquery~10 mins

Scalar types (String, Int, Float, Boolean, ID) in GraphQL - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Scalar types (String, Int, Float, Boolean, ID)
Start: Define Scalar Type
Choose one of: String, Int, Float, Boolean, ID
Assign value matching type
Use value in query or mutation
GraphQL validates type
Return or store value
End
This flow shows how a scalar type is chosen, assigned a value, validated by GraphQL, and then used in queries or mutations.
Execution Sample
GraphQL
type Query {
  getUserName(id: ID!): String
}

query {
  getUserName(id: "123")
}
This GraphQL query requests a user name by providing an ID of type ID, expecting a String result.
Execution Table
StepActionInput/ValueType CheckedResult/Output
1Receive argument 'id'"123"IDValid ID string
2Validate argument type"123"IDPasses validation
3Execute resolver getUserNameid = "123"IDReturns user name as String
4Return result to client"Alice"StringQuery result: "Alice"
5End of query execution---
💡 Query completes after returning a String result matching the schema.
Variable Tracker
VariableStartAfter Step 1After Step 3Final
idundefined"123""123""123"
resultundefinedundefined"Alice""Alice"
Key Moments - 2 Insights
Why must the ID type value be a string and not a number?
The ID scalar in GraphQL is serialized as a string to allow flexibility (like UUIDs). In the execution_table step 1 and 2, the value "123" is treated as a string, not a number.
What happens if the returned value does not match the declared scalar type?
GraphQL will raise a validation error before sending the response. In step 4, the returned value must be a String as declared, or the query fails.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 2, what type is the input value "123" checked against?
AString
BInt
CID
DBoolean
💡 Hint
Check the 'Type Checked' column at step 2 in the execution_table.
At which step does the resolver return the user name as a String?
AStep 3
BStep 1
CStep 4
DStep 5
💡 Hint
Look at the 'Action' and 'Result/Output' columns in the execution_table.
If the id argument was given as 123 (number) instead of "123" (string), what would happen?
AIt would pass validation as ID accepts numbers
BIt would fail validation because ID expects a string
CIt would convert automatically to string
DIt would return a Boolean false
💡 Hint
Refer to key_moments about ID type and execution_table step 2 validation.
Concept Snapshot
GraphQL Scalar Types:
- String: text data
- Int: whole numbers
- Float: decimal numbers
- Boolean: true or false
- ID: unique identifier (string)
Use scalar types to define simple data fields and validate inputs/outputs.
Full Transcript
This visual execution trace shows how GraphQL scalar types work, focusing on the ID and String types. The flow starts by defining a scalar type, then assigning a value that matches the type. The example query requests a user name by ID. The execution table traces each step: receiving the ID argument as a string, validating it as ID, executing the resolver to get a String user name, and returning the result. Variables like 'id' and 'result' are tracked through the steps. Key moments clarify why ID is a string and the importance of matching return types. The quiz tests understanding of type checking and validation. The snapshot summarizes the five main scalar types and their use in GraphQL schemas.