Bird
0
0

How can you modify a resolver to access a logging service from context and log the query arguments before returning data?

hard📝 Application Q9 of 15
GraphQL - Resolvers
How can you modify a resolver to access a logging service from context and log the query arguments before returning data?
ACall <code>context.logger.log(args)</code> before returning the result
BAdd <code>logger</code> as a resolver argument
CUse a global logger variable inside the resolver
DLog arguments inside the schema definition
Step-by-Step Solution
Solution:
  1. Step 1: Identify how to access services via context

    Services like logging are passed via context and accessed inside resolvers.
  2. Step 2: Use context.logger.log(args) to log arguments

    Calling context.logger.log(args) before returning data logs the query arguments properly.
  3. Final Answer:

    Call context.logger.log(args) before returning the result -> Option A
  4. Quick Check:

    Use context to access services like logger [OK]
Quick Trick: Use context to access utilities like logger [OK]
Common Mistakes:
  • Adding logger as resolver parameter
  • Using global variables instead of context
  • Trying to log inside schema

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GraphQL Quizzes