Bird
Raised Fist0
GraphQLquery~20 mins

Info argument in GraphQL - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Info Argument Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate
1:30remaining
Understanding the Info Argument Structure
Given a GraphQL resolver function that receives the info argument, what does info.fieldName return?
GraphQL
function resolver(parent, args, context, info) {
  return info.fieldName;
}
AThe root query type name
BThe entire GraphQL query string sent by the client
CThe context object passed to all resolvers
DThe name of the field currently being resolved
Attempts:
2 left
💡 Hint
Think about what part of the query the resolver is working on.
❓ query_result
intermediate
2:00remaining
Using Info to Access Requested Subfields
In a resolver, how can you use the info argument to find out which subfields the client requested for a nested object?
GraphQL
function resolver(parent, args, context, info) {
  // What property of info helps here?
  return Object.keys(info.fieldNodes[0].selectionSet.selections);
}
Ainfo.schema.getType() returns the requested subfields
Binfo.fieldNodes[0].selectionSet.selections contains the requested subfields
Cinfo.variableValues holds the subfield names
Dinfo.rootValue contains the subfield list
Attempts:
2 left
💡 Hint
Look inside the AST nodes in the info argument.
📝 Syntax
advanced
1:30remaining
Correct Usage of Info Argument in Resolver Signature
Which of the following resolver function signatures correctly includes the info argument as the fourth parameter?
Afunction resolver(parent, args, context, info) { return info.fieldName; }
Bfunction resolver(info, parent, args, context) { return info.fieldName; }
Cfunction resolver(parent, info, args, context) { return info.fieldName; }
Dfunction resolver(parent, args, info) { return info.fieldName; }
Attempts:
2 left
💡 Hint
Remember the standard order of resolver parameters.
🧠 Conceptual
advanced
1:30remaining
Purpose of the Info Argument in GraphQL Resolvers
What is the main purpose of the info argument passed to GraphQL resolvers?
ATo store user authentication tokens for security checks
BTo hold the database connection object for queries
CTo provide detailed information about the execution state, including the query AST and schema details
DTo cache previous query results for faster responses
Attempts:
2 left
💡 Hint
Think about what extra data the resolver might need about the query itself.
🔧 Debug
expert
2:00remaining
Diagnosing a TypeError Using the Info Argument
A resolver function tries to access info.fieldNodes.selectionSet.selections but throws a TypeError: Cannot read property 'selectionSet' of undefined. What is the most likely cause?
GraphQL
function resolver(parent, args, context, info) {
  return info.fieldNodes.selectionSet.selections;
}
Ainfo.fieldNodes is an array, so accessing selectionSet directly causes the error
Binfo.fieldNodes is null because the query is empty
Cinfo.selectionSet is undefined because it does not exist on info
DThe resolver forgot to pass the info argument
Attempts:
2 left
💡 Hint
Check the type of info.fieldNodes and how to access its elements.

Practice

(1/5)
1. What is the purpose of the info argument in a GraphQL resolver?
easy
A. It stores the database connection details.
B. It contains the user's authentication token.
C. It tells the resolver which fields the client requested.
D. It defines the schema of the GraphQL server.

Solution

  1. Step 1: Understand the role of resolver arguments

    Resolvers receive arguments like parent, args, context, and info. Each has a specific role.
  2. Step 2: Identify what info provides

    The info argument contains details about the query, including which fields the client requested.
  3. Final Answer:

    It tells the resolver which fields the client requested. -> Option C
  4. Quick Check:

    Info argument = requested fields [OK]
Hint: Info shows requested fields to optimize data fetching [OK]
Common Mistakes:
  • Confusing info with context or args
  • Thinking info holds authentication data
  • Assuming info defines schema
2. Which of the following is the correct way to include the info argument in a GraphQL resolver function?
easy
A. resolver(parent, args, context, info) { ... }
B. resolver(args, parent, info, context) { ... }
C. resolver(context, info, args, parent) { ... }
D. resolver(info, parent, args, context) { ... }

Solution

  1. Step 1: Recall the standard resolver signature

    The standard order is (parent, args, context, info) in GraphQL resolvers.
  2. Step 2: Match the correct order

    resolver(parent, args, context, info) { ... } matches this order exactly, making it the correct syntax.
  3. Final Answer:

    resolver(parent, args, context, info) { ... } -> Option A
  4. Quick Check:

    Resolver args order = parent, args, context, info [OK]
Hint: Remember resolver args order: parent, args, context, info [OK]
Common Mistakes:
  • Mixing up the order of arguments
  • Placing info before context
  • Omitting info argument
3. Given this resolver snippet, what will info.fieldNodes[0].selectionSet.selections.map(f => f.name.value) return if the client queries { user { id name } }?
medium
A. ["id", "name"]
B. ["user"]
C. ["id"]
D. An empty array []

Solution

  1. Step 1: Understand the query structure

    The client requests the fields id and name inside user.
  2. Step 2: Analyze the info.fieldNodes access

    info.fieldNodes[0].selectionSet.selections lists the fields requested inside user, which are id and name.
  3. Final Answer:

    ["id", "name"] -> Option A
  4. Quick Check:

    info.fieldNodes selections = requested fields [OK]
Hint: info.fieldNodes lists requested fields inside current resolver [OK]
Common Mistakes:
  • Returning parent field name instead of subfields
  • Confusing selectionSet with fieldNodes
  • Expecting only one field instead of all requested
4. You wrote this resolver: function resolver(parent, args, context) { return info.fieldNodes; }. Why does this cause an error?
medium
A. You cannot access fieldNodes inside resolvers.
B. The resolver is missing the info argument in its parameters.
C. The info argument must be the first parameter.
D. Resolvers cannot return objects like fieldNodes.

Solution

  1. Step 1: Check resolver parameters

    The resolver only has three parameters: parent, args, context. It lacks the fourth parameter info.
  2. Step 2: Understand usage of info

    Since info is not declared, trying to use it causes a reference error.
  3. Final Answer:

    The resolver is missing the info argument in its parameters. -> Option B
  4. Quick Check:

    Missing info param = error [OK]
Hint: Always include info as fourth parameter to use it [OK]
Common Mistakes:
  • Forgetting to add info parameter
  • Assuming info is global or in context
  • Misordering resolver parameters
5. 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
A. Fetch all fields but filter results after sending to client.
B. Ignore info and always fetch all fields from the database.
C. Use args to guess which fields the client wants.
D. Use info.fieldNodes to find requested fields and fetch only those from the database.

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]
Hint: 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
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard