Docblock tags
Info
Besides the arguments and the context, each resolver method or function may also read the info object. It holds information about the current execution: the field's name, its type, and the field's AST node among them. It is mostly used for advanced features, such as optimizations.
Gratos detects every resolver parameter typed with the GqlInfo type you import from gratos:
import type { GqlInfo } from "gratos";
/** @gqlQueryField */
export function greeting(info: GqlInfo): string {
return `Greetings from the ${info.fieldName} field!`;
}type Query {
greeting: String
}Warning
Use the GqlInfo that gratos exports, not graphql-js's GraphQLResolveInfo type. Both are the same TypeScript type, but Gratos cannot statically "see" the graphql-js one, so it would not pass the info object to your resolver.
Tip
Unlike graphql-js, Gratos does not require the info object to be a specific positional argument of the resolver. Put it anywhere among the field's own parameters, as long as its type is GqlInfo. The one fixed position is the parent: a function or static method that defines a field on a type other than Query, Mutation or Subscription takes the parent object first, so its info comes after it.
With gratos-server's jit() plugin, an operation that selects a field whose resolver takes a GqlInfo parameter runs on graphql-js, not graphql-jit: graphql-jit's info object has no getAbortSignal(), so Gratos marks such a field jit: false (see Effect resolvers).