Introduction
Relay specification compliance helps organize data fetching in GraphQL so apps can load data efficiently and smoothly.
Jump into concepts and practice - no test required
type Query {
items(first: Int, after: String): ItemConnection
}
type ItemConnection {
edges: [ItemEdge]
pageInfo: PageInfo
}
type ItemEdge {
node: Item
cursor: String
}
type PageInfo {
hasNextPage: Boolean
endCursor: String
}query {
items(first: 5, after: "cursor123") {
edges {
node {
id
name
}
cursor
}
pageInfo {
hasNextPage
endCursor
}
}
}type UserConnection {
edges: [UserEdge]
pageInfo: PageInfo
}
type UserEdge {
node: User
cursor: String
}query {
books(first: 3) {
edges {
node {
id
title
}
cursor
}
pageInfo {
hasNextPage
endCursor
}
}
}edges field in a Relay-compliant GraphQL connection?edges to represent each item with its cursor for pagination.edgesedges field contains nodes (items) and cursors, enabling smooth pagination.edges = items + cursors [OK]users?first to specify how many items to fetch from the start.first: 5 is valid; limit, count, and take are not Relay standard arguments.first for Relay pagination [OK]{ posts(first: 2) { edges { cursor node { title } } pageInfo { hasNextPage } } }{ "data": { "posts": { "edges": [ { "cursor": "cursor1", "node": { "title": "Post A" } }, { "cursor": "cursor2", "node": { "title": "Post B" } } ], "pageInfo": { "hasNextPage": true } } } }hasNextPage indicate?pageInfo.hasNextPagetrue means more posts exist after the fetched two.hasNextPage = true means more data [OK]{ comments(last: 3) { edges { node { text } } } }"Field 'last' is not supported on this connection"
first and backward with last.last is unsupported.endCursor for next page.after: "endCursor" to continue pagination forward.