Bird
Raised Fist0
GraphQLquery~20 mins

Scalar types (String, Int, Float, Boolean, ID) in GraphQL - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Scalar Type Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate
2:00remaining
What is the output of this GraphQL query with scalar types?

Given the following GraphQL schema snippet:

type Product {
  id: ID!
  name: String!
  price: Float!
  inStock: Boolean!
  quantity: Int!
}

And this query:

{
  product {
    id
    name
    price
    inStock
    quantity
  }
}

Assuming the product data is: {id: "p123", name: "Pen", price: 1.5, inStock: true, quantity: 100}, what is the expected JSON response?

A{"data": {"product": {"id": 123, "name": "Pen", "price": "1.5", "inStock": "true", "quantity": "100"}}}
B{"data": {"product": {"id": "p123", "name": "Pen", "price": 1.5, "inStock": true, "quantity": 100}}}
C{"data": {"product": {"id": "p123", "name": "Pen", "price": 1, "inStock": true, "quantity": 100}}}
D{"data": {"product": {"id": "p123", "name": "Pen", "price": 1.5, "inStock": "true", "quantity": 100}}}
Attempts:
2 left
💡 Hint

Remember that ID and String are returned as strings, Float as a number with decimals, Boolean as true/false, and Int as an integer.

🧠 Conceptual
intermediate
1:30remaining
Which scalar type is best for a unique user identifier in GraphQL?

You want to store a unique identifier for each user in your GraphQL schema. Which scalar type should you use?

ABoolean
BString
CInt
DID
Attempts:
2 left
💡 Hint

Think about the type designed specifically for unique identifiers.

📝 Syntax
advanced
2:00remaining
Identify the syntax error in this GraphQL scalar type declaration

Which option contains a syntax error in defining a GraphQL type with scalar fields?

type Book {
  title: String!
  pages: Int
  price: Float!
  available: Boolean!
  isbn: ID!
}
Atype Book { title: String! pages: Int price: Float! available: Boolean isbn: ID! }
Btype Book { title: String! pages: Int! price: Float! available: Boolean! isbn: ID! }
Ctype Book { title: String! pages: Int price: Float available: Boolean! isbn: ID! }
Dtype Book { title: String! pages: Int price: Float! available: Boolean! isbn: ID! }
Attempts:
2 left
💡 Hint

Check the use of non-nullable markers ! and missing punctuation.

🔧 Debug
advanced
2:30remaining
Why does this GraphQL query return null for a Float field?

Given this schema:

type Item {
  id: ID!
  cost: Float!
}

And this query:

{
  item {
    id
    cost
  }
}

The server returns:

{
  "data": {
    "item": {
      "id": "i1",
      "cost": null
    }
  }
}

Why is cost null despite being non-nullable?

AThe resolver for cost returned null or undefined, violating the non-null rule.
BThe Float scalar type cannot return null values by design.
CThe ID type must be used for cost instead of Float.
DThe query is missing a required argument for cost.
Attempts:
2 left
💡 Hint

Consider what happens if a resolver returns null for a non-nullable field.

❓ optimization
expert
3:00remaining
Optimize schema design for a large dataset with many Boolean flags

You have a GraphQL schema with a type UserSettings that has 20 Boolean fields representing different feature toggles. Querying all these fields causes performance issues. What is the best way to optimize the schema design?

AReplace the 20 Boolean fields with a single String field containing a JSON-encoded object of flags.
BChange all Boolean fields to Float to reduce size.
CUse a single Int field as a bitmask to represent all 20 Boolean flags and decode on the client.
DKeep all 20 Boolean fields as is because scalar types are always efficient.
Attempts:
2 left
💡 Hint

Think about how to compact multiple true/false values efficiently.

Practice

(1/5)
1. Which of the following is NOT a standard GraphQL scalar type?
easy
A. Boolean
B. String
C. Date
D. ID

Solution

  1. Step 1: Recall standard GraphQL scalar types

    The standard scalar types are String, Int, Float, Boolean, and ID.
  2. Step 2: Identify the non-standard type

    Date is not a built-in scalar type in GraphQL; it requires a custom scalar.
  3. Final Answer:

    Date -> Option C
  4. Quick Check:

    Standard scalars exclude Date [OK]
Hint: Remember only 5 built-in scalars: String, Int, Float, Boolean, ID [OK]
Common Mistakes:
  • Thinking Date is built-in
  • Confusing ID with Int
  • Assuming Boolean is custom
2. Which of the following is the correct way to declare a field of type ID in a GraphQL schema?
easy
A. userId: id
B. userId: Int
C. userId: String!
D. userId: ID!

Solution

  1. Step 1: Understand GraphQL type syntax

    Types are case-sensitive; ID must be uppercase and non-null indicated by !.
  2. Step 2: Check each option

    userId: ID! uses correct type 'ID!' with uppercase and non-null. Others are either lowercase or wrong type.
  3. Final Answer:

    userId: ID! -> Option D
  4. Quick Check:

    ID type is uppercase and non-null with ! [OK]
Hint: ID type is uppercase and ! means non-null [OK]
Common Mistakes:
  • Using lowercase 'id'
  • Confusing ID with String
  • Omitting ! for required fields
3. Given this GraphQL query result for a field declared as Float:
{ price: 19 }
What is the actual type of the returned value?
medium
A. Float
B. String
C. Integer
D. Boolean

Solution

  1. Step 1: Understand GraphQL Float type

    Float represents decimal numbers but can also return whole numbers as floats.
  2. Step 2: Analyze the value 19

    Even though 19 looks like an integer, GraphQL returns it as a Float type because the field is Float.
  3. Final Answer:

    Float -> Option A
  4. Quick Check:

    Float fields return numbers as floats, even whole numbers [OK]
Hint: Float fields always return float type, even if whole number [OK]
Common Mistakes:
  • Assuming 19 is Integer
  • Thinking Float must have decimal point
  • Confusing with String
4. Identify the error in this GraphQL schema snippet:
type Product {
  id: ID
  name: String!
  price: float
  inStock: Boolean
}
medium
A. 'Boolean' should be lowercase 'boolean'
B. 'float' should be 'Float' with uppercase F
C. 'ID' should be 'Id' with lowercase d
D. 'String!' should be 'String' without exclamation mark

Solution

  1. Step 1: Check scalar type capitalization

    GraphQL scalar types are case-sensitive; 'Float' must be capitalized.
  2. Step 2: Verify other types

    'Boolean' and 'ID' are correctly capitalized; 'String!' is valid for non-null.
  3. Final Answer:

    'float' should be 'Float' with uppercase F -> Option B
  4. Quick Check:

    Scalar types must be capitalized exactly [OK]
Hint: Scalar types always start with uppercase letter [OK]
Common Mistakes:
  • Using lowercase scalar types
  • Changing Boolean case
  • Removing ! from non-null
5. You want to store a unique identifier for users that is a string but should never be null. Which scalar type and modifier combination is best in GraphQL schema?
hard
A. ID!
B. String
C. Int!
D. Boolean!

Solution

  1. Step 1: Understand the purpose of ID scalar

    ID is designed for unique identifiers and is serialized as string.
  2. Step 2: Ensure non-null constraint

    Adding ! means the field cannot be null, which fits the requirement.
  3. Final Answer:

    ID! -> Option A
  4. Quick Check:

    Use ID! for unique, non-null string identifiers [OK]
Hint: Use ID! for unique, required string IDs [OK]
Common Mistakes:
  • Using String without !
  • Using Int for string IDs
  • Using Boolean for IDs
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard