A List type in GraphQL represents an array of values of a specific type. It allows you to return multiple items instead of just one.
Click to reveal answer
beginner
How do you define a List type in a GraphQL schema?
You define a List type by wrapping the type in square brackets. For example, [String] means a list of strings.
Click to reveal answer
intermediate
What does [Int!]! mean in GraphQL?
It means a non-null list of non-null integers. The list itself cannot be null, and none of the integers inside can be null.
Click to reveal answer
beginner
Can a List type contain different types of values in GraphQL?
No, a List type must contain values of the same specified type. For example, [String] can only contain strings.
Click to reveal answer
beginner
Why use List types in GraphQL queries?
List types let you fetch multiple related items in one query, like a list of users or posts, making data fetching efficient and organized.
Click to reveal answer
How do you represent a list of strings in GraphQL schema?
A[String]
BString[]
CList<String>
D{String}
✗ Incorrect
In GraphQL, list types are represented by square brackets around the type, like [String].
What does the exclamation mark (!) mean in GraphQL types?
AThe value is a list
BThe value is optional
CThe value cannot be null
DThe value is a string
✗ Incorrect
An exclamation mark means the value cannot be null, ensuring it must always have a value.
Which of these is a valid GraphQL list type for non-null integers?
A[Int!]
B[Int]
CInt!
DInt[]
✗ Incorrect
[Int!] means a list of integers where each integer cannot be null.
Can a GraphQL list contain different types like [String, Int]?
AYes, lists can mix types
BNo, lists must have one type only
COnly if wrapped in a union type
DOnly if marked nullable
✗ Incorrect
GraphQL lists must contain values of the same type; mixing types is not allowed.
What is the benefit of using list types in GraphQL queries?
ATo limit query depth
BTo make queries faster by skipping data
CTo avoid using variables
DTo fetch multiple items in one query
✗ Incorrect
List types allow fetching multiple related items in a single query, improving efficiency.
Explain how to define and use List types in GraphQL schemas.
Think about how you would describe an array of items in GraphQL.
You got /4 concepts.
Describe the importance of List types when querying data in GraphQL.
Consider why you might want to get many records instead of just one.
You got /4 concepts.
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
Step 1: Understand list notation in GraphQL
Square brackets [] indicate a list type that holds multiple values of the same type.
Step 2: Interpret [Int]
This means a list containing zero or more integers.
Final Answer:
A collection of integers -> Option C
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
Step 1: Recall GraphQL list syntax
GraphQL uses square brackets [] around a type to define a list.
Step 2: Identify correct option
[String] is the correct way to define a list of strings in GraphQL.
Final Answer:
[String] -> Option B
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
Step 1: Understand the field type
favoriteNumbers is a list of integers, so the response must be a list (array) of numbers.
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.
Final Answer:
[1, 2, 3] -> Option D
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
Step 1: Check list type syntax
List types require both opening and closing square brackets around the type.
Step 2: Locate syntax error
The closing bracket "]" is missing after String, causing a syntax error.
Final Answer:
Missing closing bracket "]" for the list type -> Option A
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
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.
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.
Final Answer:
[Int!] -> Option A
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 unknownstrongwhile earning +1 Grip toward your certificate.