Bird
0
0

You want to optimize a GraphQL query to avoid both over-fetching and under-fetching when fetching user data and their recent posts. Which approach is best?

hard📝 Application Q8 of 15
GraphQL - Basics and Philosophy
You want to optimize a GraphQL query to avoid both over-fetching and under-fetching when fetching user data and their recent posts. Which approach is best?
ARequest only user ID and fetch posts in a separate query
BRequest user name only and fetch posts later if needed
CRequest all user fields and all post fields in one query
DRequest user name and posts with only titles in one query
Step-by-Step Solution
Solution:
  1. Step 1: Understand the goal

    Avoid over-fetching and under-fetching by getting exactly needed data in one query.
  2. Step 2: Evaluate options

    Request user name and posts with only titles in one query requests user name and posts with only titles, matching needed data without extras or misses.
  3. Final Answer:

    Request user name and posts with only titles in one query -> Option D
  4. Quick Check:

    Exact needed fields in one query = Optimal [OK]
Quick Trick: Fetch exactly needed fields in one query to optimize [OK]
Common Mistakes:
  • Splitting data into multiple queries causing under-fetching
  • Requesting all fields causing over-fetching
  • Requesting too few fields causing extra queries

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GraphQL Quizzes