0
0
GraphQLquery~10 mins

Connection pattern (edges, nodes, pageInfo) in GraphQL - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Connection pattern (edges, nodes, pageInfo)
Client requests connection
Server fetches data list
Wrap data in edges with cursor
Extract nodes from edges
Create pageInfo with cursors and hasNextPage
Return connection object
Client receives edges, nodes, pageInfo
The client asks for a list with pagination info; the server wraps items as edges with cursors, extracts nodes, builds pageInfo, and returns all.
Execution Sample
GraphQL
query {
  users(first: 2, after: "cursor1") {
    edges {
      cursor
      node {
        id
        name
      }
    }
    nodes {
      id
      name
    }
    pageInfo {
      hasNextPage
      endCursor
    }
  }
}
This query asks for the first 2 users after a cursor, requesting edges with cursors and nodes, plus pageInfo.
Execution Table
StepActionData StateOutput Part
1Receive query with first=2, after='cursor1'No data fetched yetStart processing
2Fetch users after cursor1Fetched users: [{id:3,name:'C'}, {id:4,name:'D'}, {id:5,name:'E'}]Data ready for pagination
3Select first 2 usersSelected users: [{id:3,name:'C'}, {id:4,name:'D'}]Subset for response
4Create edges with cursorsEdges: [{cursor:'cursor3', node:{id:3,name:'C'}}, {cursor:'cursor4', node:{id:4,name:'D'}}]Edges array
5Extract nodes from edgesNodes: [{id:3,name:'C'}, {id:4,name:'D'}]Nodes array
6Build pageInfopageInfo: {hasNextPage:true, endCursor:'cursor4'}Pagination info
7Return connection objectEdges, Nodes, pageInfo readyComplete response sent
8Client receives responseEdges with cursors, nodes, pageInfoQuery result
💡 All requested data prepared and returned to client
Variable Tracker
VariableStartAfter Step 2After Step 3After Step 4After Step 5After Step 6Final
fetchedUsers[][{id:3,name:'C'},{id:4,name:'D'},{id:5,name:'E'}][{id:3,name:'C'},{id:4,name:'D'}][{id:3,name:'C'},{id:4,name:'D'}][{id:3,name:'C'},{id:4,name:'D'}][{id:3,name:'C'},{id:4,name:'D'}][{id:3,name:'C'},{id:4,name:'D'}]
edges[][][][{cursor:'cursor3',node:{id:3,name:'C'}},{cursor:'cursor4',node:{id:4,name:'D'}}][{cursor:'cursor3',node:{id:3,name:'C'}},{cursor:'cursor4',node:{id:4,name:'D'}}][{cursor:'cursor3',node:{id:3,name:'C'}},{cursor:'cursor4',node:{id:4,name:'D'}}][{cursor:'cursor3',node:{id:3,name:'C'}},{cursor:'cursor4',node:{id:4,name:'D'}}]
nodes[][][][][{id:3,name:'C'},{id:4,name:'D'}][{id:3,name:'C'},{id:4,name:'D'}][{id:3,name:'C'},{id:4,name:'D'}]
pageInfo{}{}{}{}{}{hasNextPage:true,endCursor:'cursor4'}{hasNextPage:true,endCursor:'cursor4'}
Key Moments - 3 Insights
Why do we have both edges and nodes in the response?
Edges include cursors for pagination and the node data; nodes are just the data items. This lets clients use cursors for paging (see execution_table step 4 and 5).
What does pageInfo's hasNextPage mean?
It tells if more data exists after the current page. In step 6, we set hasNextPage true because more users remain beyond the selected ones.
Why do we use cursors instead of page numbers?
Cursors point to exact positions in data, making pagination reliable even if data changes. This is shown in step 4 where each edge has a cursor.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 4, what does each edge contain?
AOnly the user data without cursor
BA cursor and the user data node
COnly the cursor string
DPageInfo information
💡 Hint
Check the 'Output Part' column at step 4 in execution_table
At which step does the server decide how many users to return?
AStep 3
BStep 2
CStep 5
DStep 6
💡 Hint
Look at 'Action' and 'Data State' columns in execution_table for step 3
If there were no more users after the selected ones, what would pageInfo.hasNextPage be?
Anull
Btrue
Cfalse
Dundefined
💡 Hint
Refer to pageInfo meaning in key_moments and execution_table step 6
Concept Snapshot
Connection pattern returns paginated lists.
Data is wrapped in edges with cursors.
Nodes are extracted data items.
pageInfo shows pagination state (hasNextPage, endCursor).
Clients use cursors to fetch next pages reliably.
Full Transcript
The connection pattern in GraphQL helps clients get lists with pagination. The client sends a query asking for a number of items after a cursor. The server fetches the full list, then selects the requested slice. It wraps each item in an edge object that includes a cursor and the node data. Nodes are extracted as a simple list of data items. The server also creates pageInfo with information like whether more pages exist and the cursor of the last item. This connection object is returned to the client. The client uses edges and pageInfo to navigate pages smoothly. This pattern avoids problems with page numbers and changing data. The execution table shows each step from receiving the query, fetching data, slicing, wrapping edges, extracting nodes, building pageInfo, and returning the response. Variables track the data state at each step. Key moments clarify why edges and nodes both exist, what pageInfo means, and why cursors are used. The quiz tests understanding of edges content, when slicing happens, and pageInfo meaning. The snapshot summarizes the pattern in a few lines for quick recall.