Bird
0
0

You want your resolver to return only the fields requested by the client to save resources. Which approach using the info argument is best?

hard📝 Application Q15 of 15
GraphQL - Resolvers
You want your resolver to return only the fields requested by the client to save resources. Which approach using the info argument is best?
AFetch all fields but filter results after sending to client.
BIgnore <code>info</code> and always fetch all fields from the database.
CUse <code>args</code> to guess which fields the client wants.
DUse <code>info.fieldNodes</code> to find requested fields and fetch only those from the database.
Step-by-Step Solution
Solution:
  1. Step 1: Understand the goal

    The goal is to fetch only requested fields to save resources.
  2. Step 2: Use info to get requested fields

    info.fieldNodes provides the exact fields the client asked for, so you can fetch only those.
  3. Step 3: Compare options

    Use info.fieldNodes to find requested fields and fetch only those from the database. uses info correctly. Options B, C, and D either waste resources or guess incorrectly.
  4. Final Answer:

    Use info.fieldNodes to find requested fields and fetch only those from the database. -> Option D
  5. Quick Check:

    Use info to fetch requested fields only [OK]
Quick Trick: Fetch only requested fields using info to save resources [OK]
Common Mistakes:
  • Fetching all data regardless of request
  • Using args instead of info for fields
  • Filtering after fetching all data

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GraphQL Quizzes