UNPKG

@nestjs/graphql

Version:

GraphQL for NestJS: code-first and schema-first APIs, resolvers as providers, subscriptions, federation and generated SDL, on Apollo or Mercurius.

57 lines • 2.75 kB
import { IResolvers } from '@graphql-tools/utils'; import { Logger } from '@nestjs/common'; import { GraphQLFieldResolver, GraphQLNamedType, GraphQLSchema } from 'graphql'; import { FieldMiddleware } from '../interfaces/index.js'; type FieldResolver = GraphQLFieldResolver<unknown, unknown>; export interface FieldResolverBinderOptions { /** * The schema that the resolvers were added to (e.g., with * "makeExecutableSchema()"). The resolvers bound to the fields are read from * it when the binder is created, so its fields may be rebound afterwards. */ executableSchema: GraphQLSchema; /** * The resolvers that were added to "executableSchema". */ resolvers: IResolvers; /** * Returns a type of the auto-generated (code-first) schema. */ getType: (typeName: string) => GraphQLNamedType | undefined; /** * The global field middleware ("buildSchemaOptions.fieldMiddleware"). */ globalMiddleware: FieldMiddleware[]; } /** * Binds the field resolvers to the fields of the object types of a code-first * schema. "GraphQLFactory" and "GraphQLFederationFactory" both use it, so that * a field is bound the same way on every driver. */ export declare function createFieldResolverBinder({ executableSchema, resolvers, getType, globalMiddleware, }: FieldResolverBinderOptions): { /** * Returns the resolver to bind to a field of an object type (other than * a root type), or "undefined" to keep the one the field has: * - the resolver of the type itself or, if it has none, the one of its * most specific supertype (interfaces and parent classes), along with * the middleware that the model declares for the field; * - or else the resolver returned by "fallback"; * - or else, for a field that only a field resolver declares (the model * has no such field), a resolver that throws: such a field must not * fall back to the parent's property (fail closed). */ getFieldResolver(typeName: string, fieldName: string, fallback?: () => FieldResolver | undefined): FieldResolver | undefined; /** * Logs the fields bound to a resolver that throws (see "getFieldResolver()"). */ warnUnboundFields(logger: Logger): void; }; /** * "@graphql-tools/schema" lets the interface that a type lists last win, so * a base interface listed after an interface that implements it replaces the * resolver of the more specific interface (and the guards wrapped around it). * Binds the resolver of the most specific interface instead. */ export declare function inheritResolversFromInterfaces(schema: GraphQLSchema, resolvers: IResolvers): void; export {}; //# sourceMappingURL=resolver-binding.util.d.ts.map