0
0
GraphQLquery~20 mins

Info argument in GraphQL - Practice Problems & Coding Challenges

Choose your learning style9 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.