Pagination

Grafbase automatically generates a connection type for paginating entries. If you're fetching by collection, or fetching many relation entries then you can provide arguments to paginate.

You can use the following arguments for pagination:

  • after: String — Fetch items after the provided cursor value.
  • before: String — Fetch items before the provided cursor value.
  • first: Int — Fetch the first provided entries in the result set, max 100.
  • last: Int — Fetch the last amount of entries in the result set, max 100.

You must provide either a first or last value when paginating results.

type Post @model {
  id: ID!
  title: String
}

Items returned for first are sorted in the order in which you added them, with the first added item first in the list. For last, the first item in the list is the last item you added.

Collections return a [modelName]Connection type containing edges, and pageInfo fields of the types [[modelName]Edge] and PageInfo!, respectively.

The edges field returns the actual data as [[modelName]Edge]. Each [modelName]Edge entry contains both cursor, and node.

  • cursor — The cursor of the current item in the result set.
  • node — The current edge node. This will be of the type you're querying, for example Post.
type Post @model {
  id: ID!
  title: String
}

The PageInfo! type that is returned for the field pageInfo inside of your [modelName]Connection type provides helpful data for the purposes of pagination.

  • startCursor: String — The cursor for the node in the current paginated result set.
  • endCursor: String — The cursor for the node in the current paginated result set.
  • hasNextPage: Boolean!true or false if there's a next page of results.
  • hasPreviousPage: Boolean!true or false if there is a previous page of results.
type Post @model {
  id: ID!
  title: String
}

The previous types ([modelName]Connection, [modelName]Edge, PageInfo) and arguments (first, last, before, after) are available when you have a one-to-many, many-to-one, or many-to-many relationship between models.

type Category @model {
  id: ID!
  name: String
  posts: [Post]
}

type Post @model {
  id: ID!
  title: String
  category: Category
}