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 }?
{ numbers }Remember that [Int!]! means the list itself cannot be null and no element inside can be null.
The schema specifies numbers as a non-null list of non-null integers. The resolver returns a valid list of integers without nulls, so the query returns the list inside data.
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.
Think about which parts are nullable: the list itself and the elements inside.
[String] means the list can be null and elements can be null. Other options make either the list or elements non-null.
You have a GraphQL field items: [Item!]! returning thousands of items. Which approach optimizes performance best?
Think about how to reduce data transfer and server load.
Pagination with first and after arguments limits the number of items returned, improving performance and user experience.
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?
Check the non-null constraints on list elements.
The list is non-null and elements are non-null. Returning a null element violates User! and causes an error.
Explain the difference between the GraphQL list types [String!] and [String] in terms of nullability of the list and its elements.
Focus on which parts the exclamation mark applies to: the list or the elements.
[String!] means a list that may be null but all elements inside must be non-null strings. [String] means the list may be null and elements may also be null.