info argument, what does info.fieldName return?function resolver(parent, args, context, info) { return info.fieldName; }
The info.fieldName property contains the name of the field that the resolver is currently resolving. It helps identify which field in the query is being processed.
info argument to find out which subfields the client requested for a nested object?function resolver(parent, args, context, info) { // What property of info helps here? return Object.keys(info.fieldNodes[0].selectionSet.selections); }
The info.fieldNodes array contains the AST nodes for the current field. The first node's selectionSet.selections holds the subfields requested by the client.
info argument as the fourth parameter?The standard resolver function parameters order is parent, args, context, then info. Only option A follows this order correctly.
info argument passed to GraphQL resolvers?The info argument contains the GraphQL query's abstract syntax tree (AST), schema information, and execution state, which helps resolvers understand the query structure and requested fields.
info.fieldNodes.selectionSet.selections but throws a TypeError: Cannot read property 'selectionSet' of undefined. What is the most likely cause?function resolver(parent, args, context, info) { return info.fieldNodes.selectionSet.selections; }
info.fieldNodes is an array of AST nodes. Trying to access selectionSet directly on the array causes the error. The correct access is info.fieldNodes[0].selectionSet.