UNPKG

@graphql-yoga/nestjs

Version:
47 lines (46 loc) • 2.8 kB
import type { Express, Request as ExpressRequest, Response as ExpressResponse } from 'express'; import type { FastifyInstance, FastifyReply, FastifyRequest } from 'fastify'; import { YogaSchemaDefinition, YogaServerInstance, YogaServerOptions } from 'graphql-yoga'; import { AbstractGraphQLDriver, GqlModuleOptions } from '@nestjs/graphql'; export type YogaDriverPlatform = 'express' | 'fastify'; export type YogaDriverServerContext<Platform extends YogaDriverPlatform> = Platform extends 'fastify' ? { req: FastifyRequest; reply: FastifyReply; } : { req: ExpressRequest; res: ExpressResponse; }; export type YogaDriverServerOptions<Platform extends YogaDriverPlatform> = Omit<YogaServerOptions<YogaDriverServerContext<Platform>, never>, 'context' | 'schema' | 'graphqlEndpoint'> & { conditionalSchema?: YogaSchemaDefinition<YogaDriverServerContext<Platform>, never> | undefined; }; export type YogaDriverServerInstance<Platform extends YogaDriverPlatform> = YogaServerInstance<YogaDriverServerContext<Platform>, never>; export type YogaDriverConfig<Platform extends YogaDriverPlatform = 'express'> = GqlModuleOptions & YogaDriverServerOptions<Platform> & ({ /** * Subscriptions configuration. Passing `true` will install only `graphql-ws`. */ conditionalSchema?: never; } | { /** * TODO: Support conditional schema with subscriptions */ subscriptions?: never; conditionalSchema?: YogaSchemaDefinition<YogaDriverServerContext<Platform>, never> | undefined; }); export declare abstract class AbstractYogaDriver<Platform extends YogaDriverPlatform> extends AbstractGraphQLDriver<YogaDriverConfig<Platform>> { protected yoga: YogaDriverServerInstance<Platform>; start(options: YogaDriverConfig<Platform>): Promise<void>; stop(): Promise<void>; protected registerExpress({ conditionalSchema, ...options }: YogaDriverConfig<'express'>, { preStartHook }?: { preStartHook?: (app: Express) => void; }): void; protected registerFastify({ conditionalSchema, ...options }: YogaDriverConfig<'fastify'>, { preStartHook }?: { preStartHook?: (app: FastifyInstance) => void; }): void; private mergeConditionalSchema; subscriptionWithFilter<TPayload, TVariables, TContext>(instanceRef: unknown, filterFn: (payload: TPayload, variables: TVariables, context: TContext) => boolean | Promise<boolean>, createSubscribeContext: Function): (args_0: TPayload, args_1: TVariables, args_2: TContext) => Promise<import("graphql-yoga").Repeater<TPayload, void, unknown>>; } export declare class YogaDriver<Platform extends YogaDriverPlatform = 'express'> extends AbstractYogaDriver<Platform> { private subscriptionService?; start(options: YogaDriverConfig<Platform>): Promise<void>; stop(): Promise<void>; }