Bird
0
0

You want to fetch a user's full profile by combining data from two sources: a database and an external API. How should you design the resolver for the userProfile field?

hard📝 Application Q15 of 15
GraphQL - Resolvers
You want to fetch a user's full profile by combining data from two sources: a database and an external API. How should you design the resolver for the userProfile field?
AFetch data only from the database and ignore the API
BDefine the schema to include both data sources without a resolver
CUse two separate resolvers for the same field to fetch data independently
DWrite a resolver that calls the database and API, then merges results before returning
Step-by-Step Solution
Solution:
  1. Step 1: Understand resolver role in combining data

    Resolvers can run code to fetch and combine data from multiple sources before returning.
  2. Step 2: Evaluate options for fetching and merging data

    Write a resolver that calls the database and API, then merges results before returning correctly describes writing a resolver that calls both sources and merges results. Other options either ignore data sources or misuse resolvers.
  3. Final Answer:

    Write a resolver that calls the database and API, then merges results before returning -> Option D
  4. Quick Check:

    Resolvers combine data sources = A [OK]
Quick Trick: Combine data in one resolver function for the field [OK]
Common Mistakes:
  • Expecting schema alone to fetch data
  • Trying multiple resolvers for one field
  • Ignoring one data source

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GraphQL Quizzes