ArticleConnection
A connection to a list of Article items, designed to support efficient cursor-based pagination. This connection type provides access to the articles themselves, their edges, pagination metadata, and the total count of articles available.
Connection Structure
{
edges: [ArticleEdge]
nodes: [Article]
pageInfo: PageInfo!
totalCount: Int
}
Pagination Arguments
The ArticleConnection
supports the following pagination arguments to navigate through the list of articles:
Argument | Type | Description | Constraints |
---|---|---|---|
first | Int | Returns the first n elements from the list after the cursor specified by after . | Must be a positive integer |
last | Int | Returns the last n elements from the list before the cursor specified by before . | Must be a positive integer |
after | String | Returns elements after the specified cursor (exclusive). | Must be a valid cursor string |
before | String | Returns elements before the specified cursor (exclusive). | Must be a valid cursor string |
These arguments enable forward and backward pagination using opaque cursors.
PageInfo Structure
The pageInfo
field provides metadata about the current page of results:
{
hasNextPage: Boolean!
hasPreviousPage: Boolean!
startCursor: String
endCursor: String
}
hasNextPage
: Indicates if there are more items when paginating forward.hasPreviousPage
: Indicates if there are more items when paginating backward.startCursor
: The cursor corresponding to the first item in the current page.endCursor
: The cursor corresponding to the last item in the current page.
These fields help clients determine navigation possibilities and construct subsequent queries.
Usage Examples
Basic Pagination
Fetch the first 5 articles with their IDs and titles:
{
articles(first: 5) {
nodes {
id
title
}
pageInfo {
hasNextPage
endCursor
}
totalCount
}
}
Forward Pagination
Fetch the next 5 articles after a given cursor:
{
articles(first: 5, after: "YXJyYXljb25uZWN0aW9uOjQ=") {
edges {
node {
id
title
}
cursor
}
pageInfo {
hasNextPage
endCursor
}
}
}
Backward Pagination
Fetch the previous 5 articles before a given cursor:
{
articles(last: 5, before: "YXJyYXljb25uZWN0aW9uOjEw") {
edges {
node {
id
title
}
cursor
}
pageInfo {
hasPreviousPage
startCursor
}
}
}
Cursor-based Navigation
Navigate through articles using cursors to fetch pages efficiently:
# Initial request to get the first page and its endCursor
{
articles(first: 3) {
edges {
node {
id
title
}
cursor
}
pageInfo {
hasNextPage
endCursor
}
}
}
# Use endCursor from previous response to fetch the next page
{
articles(first: 3, after: "YXJyYXljb25uZWN0aW9uOjM=") {
edges {
node {
id
title
}
cursor
}
pageInfo {
hasNextPage
endCursor
}
}
}
Combined with Filtering
Assuming the articles
query supports filtering by category
and sorting by publishedDate
, combine pagination with these arguments:
{
articles(first: 5, after: "YXJyYXljb25uZWN0aW9uOjU=", filter: { category: "Technology" }, sort: { field: PUBLISHED_DATE, direction: DESC }) {
nodes {
id
title
publishedDate
category
}
pageInfo {
hasNextPage
endCursor
}
totalCount
}
}
Note: Filtering and sorting arguments are examples; only use them if supported by the API.
Edge Type
The ArticleEdge
type represents a single edge in the connection and contains:
{
node: Article
cursor: String!
}
node
: The article item at the edge.cursor
: An opaque string used for pagination to identify the position of this edge.
Edges provide the link between the connection and the actual article nodes, enabling cursor-based pagination.
Pagination Best Practices
- Use
first
withafter
for forward pagination andlast
withbefore
for backward pagination to avoid ambiguous results. - Always check
pageInfo.hasNextPage
andpageInfo.hasPreviousPage
before attempting to paginate further. - Use the cursors returned in
edges.cursor
orpageInfo.startCursor
/pageInfo.endCursor
for reliable navigation. - Avoid large page sizes to reduce response times and improve performance.
- Handle empty results gracefully by checking if
nodes
oredges
arrays are empty.
Performance Considerations
- Cursor-based pagination is efficient for large datasets as it avoids offset-based scanning.
- Limit the number of items requested per page to balance response size and user experience.
- Use filtering and sorting to narrow down results before paginating.
- Cache cursors when possible to reduce repeated queries.
- Monitor rate limits when performing frequent paginated queries.
Related Types
- [
ArticleEdge
]: Represents edges in the connection, containing an article node and a cursor. - [
Article
]: The article object type containing article-specific fields. - [
PageInfo
]: Provides pagination metadata such as cursors and page availability.
Notes
- The API currently requires no authentication for querying articles, but this may change in future versions.
- Always implement error handling for invalid cursors or out-of-range pagination arguments.
- When the result set is empty,
edges
andnodes
will be empty arrays, andpageInfo.hasNextPage
andpageInfo.hasPreviousPage
will befalse
. - For single-page results, pagination arguments like
first
orlast
may return fewer items than requested, withpageInfo.hasNextPage
andpageInfo.hasPreviousPage
set accordingly. - Be mindful of rate limiting when making multiple paginated requests in quick succession.