0
0
GraphQLquery~20 mins

List types in GraphQL - Practice Problems & Coding Challenges

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