Bird
Raised Fist0
GraphQLquery~20 mins

List types in GraphQL - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
GraphQL List 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 list types?

Given the following GraphQL schema snippet:

type Query {
  numbers: [Int!]!
}

And the resolver returns: [1, 2, 3]

What will be the result of the query { numbers }?

GraphQL
{ numbers }
A{"data":{"numbers":[1,2,3]}}
B{"data":{"numbers":null}}
C{"errors":[{"message":"Cannot return null for non-nullable field Query.numbers"}]}
D{"data":{"numbers":[1,null,3]}}
Attempts:
2 left
💡 Hint

Remember that [Int!]! means the list itself cannot be null and no element inside can be null.

📝 Syntax
intermediate
1:30remaining
Which GraphQL list type syntax is valid for a list of nullable strings?

Choose the correct GraphQL type syntax for a field that returns a list which can be null, and whose elements can also be null strings.

A[String]!
B[String!]
C[String]
D[String!]!
Attempts:
2 left
💡 Hint

Think about which parts are nullable: the list itself and the elements inside.

❓ optimization
advanced
2:30remaining
How to optimize a GraphQL query fetching a large list with pagination?

You have a GraphQL field items: [Item!]! returning thousands of items. Which approach optimizes performance best?

AUse a single query without pagination and cache the result
BUse arguments like <code>first</code> and <code>after</code> to paginate the list
CChange the schema to <code>items: [Item]</code> to allow nulls
DFetch all items at once and filter on the client side
Attempts:
2 left
💡 Hint

Think about how to reduce data transfer and server load.

🔧 Debug
advanced
2:00remaining
Why does this GraphQL query return an error with list types?

Given the schema:

type Query {
  users: [User!]!
}

type User {
  id: ID!
  name: String!
}

The resolver returns [{id: "1", name: "Alice"}, null]. What error occurs and why?

AError: Field users must return a nullable list
BNo error, returns list with null element
CError: Missing required field id in User
DError: Cannot return null for non-nullable field User in list
Attempts:
2 left
💡 Hint

Check the non-null constraints on list elements.

🧠 Conceptual
expert
3:00remaining
What is the difference between [String!] and [String] in GraphQL?

Explain the difference between the GraphQL list types [String!] and [String] in terms of nullability of the list and its elements.

A<p><code>[String!]</code> means the list can be null but elements cannot be null; <code>[String]</code> means both list and elements can be null.</p>
B<p><code>[String!]</code> means the list cannot be null but elements can be null; <code>[String]</code> means list can be null but elements cannot be null.</p>
C<p><code>[String!]</code> means the list can be null and elements can be null; <code>[String]</code> means list cannot be null and elements cannot be null.</p>
D<p><code>[String!]</code> means the list cannot be null and elements cannot be null; <code>[String]</code> means list cannot be null but elements can be null.</p>
Attempts:
2 left
💡 Hint

Focus on which parts the exclamation mark applies to: the list or the elements.

Practice

(1/5)
1. What does a list type in GraphQL represent?
[Int] means a list of what?
easy
A. A string value
B. A single integer
C. A collection of integers
D. A boolean value

Solution

  1. Step 1: Understand list notation in GraphQL

    Square brackets [] indicate a list type that holds multiple values of the same type.
  2. Step 2: Interpret [Int]

    This means a list containing zero or more integers.
  3. Final Answer:

    A collection of integers -> Option C
  4. Quick Check:

    List type = multiple values [OK]
Hint: Square brackets mean list of that type [OK]
Common Mistakes:
  • Thinking it holds a single value
  • Confusing list with string or boolean
  • Ignoring the brackets meaning
2. Which of the following is the correct syntax to define a list of strings in GraphQL?
easy
A. string[]
B. [String]
C. (String[])
D. {String}

Solution

  1. Step 1: Recall GraphQL list syntax

    GraphQL uses square brackets [] around a type to define a list.
  2. Step 2: Identify correct option

    [String] is the correct way to define a list of strings in GraphQL.
  3. Final Answer:

    [String] -> Option B
  4. Quick Check:

    List syntax = brackets around type [OK]
Hint: Use square brackets around type for lists [OK]
Common Mistakes:
  • Using language-specific syntax like string[]
  • Using parentheses or curly braces instead of brackets
  • Missing brackets entirely
3. Given this GraphQL schema snippet:
type Query {
  favoriteNumbers: [Int]
}

What is a valid response for favoriteNumbers?
medium
A. {1, 2, 3}
B. 42
C. "[1, 2, 3]"
D. [1, 2, 3]

Solution

  1. Step 1: Understand the field type

    favoriteNumbers is a list of integers, so the response must be a list (array) of numbers.
  2. Step 2: Check each option

    [1, 2, 3] is a list of integers. 42 is a single integer, not a list. "[1, 2, 3]" is a string, not a list. {1, 2, 3} uses curly braces which is invalid syntax.
  3. Final Answer:

    [1, 2, 3] -> Option D
  4. Quick Check:

    List field returns list value [OK]
Hint: List fields return arrays, not single values [OK]
Common Mistakes:
  • Returning a single value instead of a list
  • Returning a string instead of a list
  • Using wrong brackets for lists
4. Identify the error in this GraphQL list type declaration:
type User {
  tags: [String
}
medium
A. Missing closing bracket "]" for the list type
B. List types cannot hold strings
C. Square brackets should be replaced with parentheses
D. Field name cannot be "tags"

Solution

  1. Step 1: Check list type syntax

    List types require both opening and closing square brackets around the type.
  2. Step 2: Locate syntax error

    The closing bracket "]" is missing after String, causing a syntax error.
  3. Final Answer:

    Missing closing bracket "]" for the list type -> Option A
  4. Quick Check:

    List syntax needs matching brackets [OK]
Hint: Always close brackets in list types [OK]
Common Mistakes:
  • Forgetting the closing bracket
  • Using wrong brackets like parentheses
  • Thinking list can't hold strings
5. You want to define a GraphQL field that can return null or a list of non-null integers, but the list itself can be empty. Which type declaration is correct?
hard
A. [Int!]
B. [Int]!
C. [Int!]!
D. Int!

Solution

  1. Step 1: Understand non-null and list syntax

    Int! means non-null integer, [Int!] means list of non-null integers, list itself can be null or empty.
  2. Step 2: Analyze options

    [Int!]: List of non-null integers, list nullable (can be empty).[Int]!: Non-null list of nullable integers.[Int!]!: Non-null list of non-null integers (list cannot be null).Int!: Single non-null integer, not a list.
  3. Final Answer:

    [Int!] -> Option A
  4. Quick Check:

    Non-null items inside nullable list = [Int!] [OK]
Hint: Non-null items inside list use [Type!] [OK]
Common Mistakes:
  • Making list itself non-null when it should be nullable
  • Confusing non-null item vs non-null list
  • Using single type instead of list
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