⬡ GraphQL
Beginner
What is the info argument in a GraphQL resolver?
Answer
The info object (fourth resolver argument) contains metadata about the current execution context. Key properties: fieldName (name of the current field), fieldNodes (AST nodes for the current field — contains the sub-selection of requested fields), returnType (the GraphQL type being returned), parentType (the type the field belongs to), schema (the full GraphQL schema), path (path from root to current field), rootValue, operation (the full query AST). Advanced use cases: inspecting which sub-fields are requested to optimize database queries (only SELECT needed columns), implementing custom caching based on types, and building field-level middleware. Libraries like graphql-fields parse the info object to extract requested fields easily.