0
0
GraphQLquery~20 mins

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

Choose your learning style9 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.