0
0
GraphQLquery~20 mins

Over-fetching and under-fetching problems in GraphQL - Practice Problems & Coding Challenges

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

Given the following GraphQL query requesting user details and their posts, what is the exact data returned?

GraphQL
query {
  user(id: "1") {
    id
    name
    posts {
      id
      title
    }
  }
}
A{"data":{"user":{"id":"1","name":"Alice","posts":[{"id":"101","title":"GraphQL Basics"},{"id":"102","title":"Advanced GraphQL"}]}}}
B{"data":{"user":{"id":"1","name":"Alice"}}}
C{"data":{"user":{"name":"Alice","posts":[{"id":"101","title":"GraphQL Basics"}]}}}
D{"data":{"user":{"id":"1","posts":[{"id":"101","title":"GraphQL Basics"}]}}}
Attempts:
2 left
💡 Hint

Check which fields are requested inside the user object.

🧠 Conceptual
intermediate
2:00remaining
Which problem does this GraphQL query cause?

This GraphQL query requests all fields of a user and all fields of their posts, including large content fields. What problem does this cause?

GraphQL
query {
  user(id: "1") {
    id
    name
    email
    posts {
      id
      title
      content
      comments {
        id
        text
      }
    }
  }
}
ANo problem: The query is perfectly optimized.
BUnder-fetching: The query misses some fields needed by the client.
CSyntax error: The query is invalid due to missing brackets.
DOver-fetching: The query requests more data than needed, causing slow responses.
Attempts:
2 left
💡 Hint

Think about the size and amount of data requested.

📝 Syntax
advanced
2:00remaining
Identify the syntax error in this GraphQL query

Find the syntax error in the following GraphQL query that fetches user and posts data.

GraphQL
query {
  user(id: "1") {
    id
    name
    posts {
      id
      title
    }
  
}
AMissing closing brace for the user field.
BMissing comma between fields.
CUsing parentheses instead of braces for posts.
DMissing quotes around the id value.
Attempts:
2 left
💡 Hint

Count the opening and closing braces carefully.

optimization
advanced
2:00remaining
How to fix under-fetching in this GraphQL query?

The client needs the user's email but the query only requests id and name. How to fix this under-fetching problem?

GraphQL
query {
  user(id: "1") {
    id
    name
  }
}
ARemove the id field from the query.
BAdd the email field inside the user selection set.
CAdd a separate query for email outside user.
DUse a mutation instead of a query.
Attempts:
2 left
💡 Hint

Think about what fields the client needs to see.

🧠 Conceptual
expert
2:00remaining
Why does GraphQL help solve over-fetching and under-fetching?

Choose the best explanation for how GraphQL addresses over-fetching and under-fetching problems compared to REST APIs.

AGraphQL automatically caches all data to prevent over-fetching.
BGraphQL forces clients to fetch all data in one request, preventing under-fetching.
CGraphQL lets clients specify exactly which fields they want, avoiding extra or missing data.
DGraphQL uses fixed endpoints that return fixed data sets.
Attempts:
2 left
💡 Hint

Think about how GraphQL queries differ from REST endpoints.