Bird
Raised Fist0
GraphQLquery~20 mins

Connection pattern (edges, nodes, pageInfo) in GraphQL - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Connection Pattern Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate
2:00remaining
What does this GraphQL query return?

Given this GraphQL query using the connection pattern, what is the structure of the returned data?

{
  users(first: 2) {
    edges {
      node {
        id
        name
      }
    }
    pageInfo {
      hasNextPage
      endCursor
    }
  }
}
A{"users":{"nodes":[{"id":"1","name":"Alice"},{"id":"2","name":"Bob"}],"pageInfo":{"hasNextPage":true,"endCursor":"cursor2"}}}
B{"users":{"edges":[{"node":{"id":"1","name":"Alice"}},{"node":{"id":"2","name":"Bob"}}],"pageInfo":{"hasNextPage":true,"endCursor":"cursor2"}}}
C{"users":[{"id":"1","name":"Alice"},{"id":"2","name":"Bob"}],"pageInfo":{"hasNextPage":true,"endCursor":"cursor2"}}
D{"users":{"edges":[{"id":"1","name":"Alice"},{"id":"2","name":"Bob"}],"pageInfo":{"hasNextPage":true,"endCursor":"cursor2"}}}
Attempts:
2 left
💡 Hint

Remember the connection pattern returns edges containing node objects, not just nodes directly.

🧠 Conceptual
intermediate
1:30remaining
Why use edges and nodes in the connection pattern?

What is the main reason the connection pattern uses edges wrapping nodes instead of returning a simple list of nodes?

ATo make the query syntax simpler and shorter.
BTo reduce the size of the response by nesting nodes inside edges.
CBecause GraphQL requires all lists to be wrapped in edges.
DTo allow adding metadata like cursors or relationship info on each edge besides the node data.
Attempts:
2 left
💡 Hint

Think about what extra information might be needed for pagination or relationships.

📝 Syntax
advanced
1:30remaining
Identify the syntax error in this connection pattern query

Which option contains a syntax error in this GraphQL connection pattern query?

{
  posts(first: 3) {
    edges {
      node {
        id
        title
      }
    }
    pageInfo {
      hasNextPage
      endCursor
    }
  }
}
A{ posts(first: 3) { edges { node { id title } } pageInfo { hasNextPage endCursor } }
B{ posts(first: 3) { edges { node { id title } } pageInfo { hasNextPage endCursor } } }
C} } } rosruCdne egaPtxeNsah { ofnIegap } } eltit di { edon { segde { )3 :tsrif(stsop {
D posts(first: 3) { edges { node { id title } } pageInfo { hasNextPage endCursor } } }
Attempts:
2 left
💡 Hint

Check for matching braces in the query.

❓ optimization
advanced
2:00remaining
Optimizing pagination with pageInfo

You want to fetch the next page of users after a cursor. Which query correctly uses pageInfo and after to get the next page?

A{ users(first: 5, after: "cursor5") { edges { node { id name } } pageInfo { hasNextPage endCursor } } }
B{ users(last: 5, before: "cursor5") { edges { node { id name } } pageInfo { hasNextPage endCursor } } }
C{ users(first: 5) { edges { node { id name } } pageInfo { hasNextPage endCursor } } }
D{ users(after: "cursor5") { edges { node { id name } } pageInfo { hasNextPage endCursor } } }
Attempts:
2 left
💡 Hint

To get the next page, use first with after cursor.

🔧 Debug
expert
2:30remaining
Why does this connection query return an empty edges array?

Given this query:

{
  comments(first: 3, after: "cursor10") {
    edges {
      node {
        id
        content
      }
    }
    pageInfo {
      hasNextPage
      endCursor
    }
  }
}

But the edges array is empty in the response, even though there are comments after cursor10. What is the most likely cause?

AThe <code>first</code> argument must be larger than 3 to get results.
BThe query is missing the <code>nodes</code> field, so edges are empty.
CThe cursor "cursor10" is invalid or does not exist in the data, so no results are returned after it.
DThe server does not support the connection pattern and returns empty edges.
Attempts:
2 left
💡 Hint

Think about what happens if the cursor is not found in the dataset.

Practice

(1/5)
1. What is the main purpose of the pageInfo field in the GraphQL connection pattern?
easy
A. To define the schema of the connection
B. To list all the nodes in the connection
C. To provide information about pagination like if there are more pages
D. To store the actual data items

Solution

  1. Step 1: Understand the role of pageInfo

    The pageInfo field contains metadata about pagination such as whether there are more pages available.
  2. Step 2: Differentiate from edges and nodes

    Unlike edges or nodes which hold data items, pageInfo only provides pagination status.
  3. Final Answer:

    To provide information about pagination like if there are more pages -> Option C
  4. Quick Check:

    pageInfo = pagination info [OK]
Hint: Remember pageInfo tells if more pages exist [OK]
Common Mistakes:
  • Confusing pageInfo with nodes or edges
  • Thinking pageInfo holds actual data items
  • Ignoring pagination metadata role
2. Which of the following is the correct way to query the edges and node fields in a GraphQL connection?
easy
A.
{ users { edge { node { id name } } } }
B.
{ users { nodes { id name } } }
C.
{ users { pageInfo { hasNextPage } } }
D.
{ users { edges { node { id name } } } }

Solution

  1. Step 1: Recall correct field names in connection pattern

    The connection pattern uses edges (plural) and inside each edge a node (singular) holds the data.
  2. Step 2: Check each option's syntax

    { users { edges { node { id name } } } }
    correctly uses edges and node.
    { users { nodes { id name } } }
    uses nodes which is valid but not with edges.
    { users { pageInfo { hasNextPage } } }
    queries only pageInfo.
    { users { edge { node { id name } } } }
    uses edge singular which is incorrect.
  3. Final Answer:

    { users { edges { node { id name } } } } -> Option D
  4. Quick Check:

    edges plural, node singular inside edges [OK]
Hint: Edges is plural; node is singular inside edges [OK]
Common Mistakes:
  • Using 'edge' instead of 'edges'
  • Mixing nodes and edges syntax
  • Querying pageInfo instead of data fields
3. Given this GraphQL query:
{ posts(first: 2) { edges { cursor node { id title } } pageInfo { hasNextPage } } }

And the server returns two posts with ids 101 and 102, what will pageInfo.hasNextPage be if there are more posts after these two?
medium
A. true
B. false
C. null
D. undefined

Solution

  1. Step 1: Understand the meaning of hasNextPage

    hasNextPage is true if more items exist beyond the current page.
  2. Step 2: Apply to given scenario

    Since the server returns 2 posts but more posts exist after them, hasNextPage must be true.
  3. Final Answer:

    true -> Option A
  4. Quick Check:

    More posts after current page means hasNextPage = true [OK]
Hint: More items after current page means hasNextPage true [OK]
Common Mistakes:
  • Assuming hasNextPage is false when items equal page size
  • Confusing hasNextPage with hasPreviousPage
  • Expecting null or undefined instead of boolean
4. You wrote this GraphQL query:
{ comments { edge { node { id text } } } }

But it returns an error. What is the likely cause?
medium
A. The field 'node' should be 'nodes'
B. The field should be 'edges' not 'edge'
C. Missing 'pageInfo' field causes error
D. The query must include 'pageInfo' and 'nodes' together

Solution

  1. Step 1: Check the connection field names

    The connection pattern uses edges (plural) not edge (singular).
  2. Step 2: Identify the error cause

    Using edge causes a field not found error because the schema expects edges.
  3. Final Answer:

    The field should be 'edges' not 'edge' -> Option B
  4. Quick Check:

    edges plural required, edge singular causes error [OK]
Hint: Use 'edges' plural, not 'edge' singular [OK]
Common Mistakes:
  • Using 'edge' instead of 'edges'
  • Thinking 'node' should be plural
  • Assuming pageInfo is mandatory for query success
5. You want to fetch a list of products with their IDs and names using the connection pattern. You only need the list of products without pagination info. Which query is best?
hard
A.
{ products { nodes { id name } } }
B.
{ products { edges { node { id name } } pageInfo { hasNextPage } } }
C.
{ products { pageInfo { hasPreviousPage } } }
D.
{ products { edges { cursor } } }

Solution

  1. Step 1: Understand the difference between nodes and edges

    nodes gives a simple list of items without pagination details, while edges includes cursors for pagination.
  2. Step 2: Choose the query matching the need

    Since pagination info is not needed, querying nodes directly is simpler and efficient.
  3. Final Answer:

    { products { nodes { id name } } } -> Option A
  4. Quick Check:

    Use nodes for simple list without pagination [OK]
Hint: Use nodes for simple lists without pagination [OK]
Common Mistakes:
  • Using edges and pageInfo when not needed
  • Querying only pageInfo without data
  • Ignoring simpler nodes field for lists
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard