UNPKG

@graphql-yoga/nestjs

Version:

GraphQL Yoga driver for NestJS GraphQL.

41 lines (40 loc) 2.29 kB
import type { Express, Request as ExpressRequest, Response as ExpressResponse } from 'express'; import type { FastifyInstance, FastifyReply, FastifyRequest } from 'fastify'; import { YogaServerInstance, YogaServerOptions } from 'graphql-yoga'; import { AbstractGraphQLDriver, GqlModuleOptions, SubscriptionConfig } 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'>; 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`. */ subscriptions?: boolean | YogaDriverSubscriptionConfig; }; export type YogaDriverSubscriptionConfig = { 'graphql-ws'?: Omit<SubscriptionConfig['graphql-ws'], 'onSubscribe'>; 'subscriptions-transport-ws'?: Omit<SubscriptionConfig['subscriptions-transport-ws'], 'onOperation'>; }; 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(options: YogaDriverConfig<'express'>, { preStartHook }?: { preStartHook?: (app: Express) => void; }): void; protected registerFastify(options: YogaDriverConfig<'fastify'>, { preStartHook }?: { preStartHook?: (app: FastifyInstance) => void; }): void; } export declare class YogaDriver<Platform extends YogaDriverPlatform = 'express'> extends AbstractYogaDriver<Platform> { private subscriptionService?; start(options: YogaDriverConfig<Platform>): Promise<void>; stop(): Promise<void>; }