Bird
0
0

How should you implement resolvers to fetch a user's profile and their associated posts from different data sources in GraphQL?

hard📝 Application Q8 of 15
GraphQL - Resolvers
How should you implement resolvers to fetch a user's profile and their associated posts from different data sources in GraphQL?
ACreate separate resolvers for <code>userProfile</code> and <code>posts</code> fields, each fetching data from their respective sources
BFetch all data in the schema definition without resolvers
CCombine all data fetching in a single resolver ignoring schema fields
DUse only one resolver for the root query that returns all nested data
Step-by-Step Solution
Solution:
  1. Step 1: Understand resolver responsibilities

    Resolvers connect schema fields to their data sources, allowing modular data fetching.
  2. Step 2: Apply modular resolver design

    Separate resolvers for userProfile and posts allow fetching from different sources efficiently.
  3. Final Answer:

    Create separate resolvers for userProfile and posts fields, each fetching data from their respective sources -> Option A
  4. Quick Check:

    Resolvers map schema fields to data sources modularly [OK]
Quick Trick: Use one resolver per field to connect schema to data source [OK]
Common Mistakes:
  • Trying to fetch all data in schema without resolvers
  • Combining unrelated data fetching in one resolver

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GraphQL Quizzes