Collection-valued fields
Schema fields that return multiple objects, such as users, products, or posts.
GraphQL · Class
GraphQLList represents a GraphQL list type whose items share a declared item type. Lists preserve order and can be combined with non-null wrappers or nested lists.
GraphQLList is the GraphQL.js wrapper used to represent a list type. It takes an item type, and that item type may itself be another wrapper, allowing combinations such as lists of non-null values or nested lists.
new GraphQLList(ofType)| Name | Type | Description |
|---|---|---|
ofType | GraphQLType | The GraphQL item type wrapped by the list; it may be a named type or another type modifier. |
A GraphQL list type whose items are serialized according to the wrapped item type.
pets: [Pet] returns a list of Pet values.const users = new GraphQLList(UserType);Wrap a GraphQL object type to declare a field that returns an ordered list of users.
Schema fields that return multiple objects, such as users, products, or posts.
Fields requiring nested collection structures, such as a matrix or grouped records.
Fields where each returned item must satisfy a non-null constraint.
GraphQLList represents a list whose items have a specified GraphQL type. In a GraphQL.js schema field, it is commonly constructed as new GraphQLList(ItemType), which corresponds to [ItemType] in GraphQL schema notation.
Follow-up: How do you require every list item to be non-null? Use new GraphQLList(new GraphQLNonNull(ItemType)), corresponding to [ItemType!].
A list type preserves item order and serializes each item according to the wrapped item type. The item type can itself be a modified type, so nested lists and lists of non-null types are supported.
Follow-up: What does [ [Int] ] express? It is a list whose items are themselves lists of integers; inner lists may contain null values unless further constrained.
A list field can produce many values, so an unconstrained list may create excessive response sizes. For potentially large list results, design the field with pagination rather than returning every item at once.
Follow-up: What other demand-control measures complement pagination? Depth, breadth or batch limits, and rate limiting can constrain costly operations.
GraphQLNonNullGraphQLObjectTypeListNon-NullofType