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.

63 lines (62 loc) • 2.27 kB
import { __decorate, __metadata } from "tslib"; import { Inject } from '@nestjs/common'; import { ApplicationConfig, HttpAdapterHost } from '@nestjs/core'; import { GraphQLFactory } from '../graphql.factory.js'; import { ResolverDecoratorHost } from '../services/resolver-decorator-host.js'; import { normalizeRoutePath } from '../utils/index.js'; /** * @publicApi */ export class AbstractGraphQLDriver { async mergeDefaultOptions(options, defaults = { path: '/graphql', fieldResolverEnhancers: [], }) { const clonedOptions = { ...defaults, ...options, }; clonedOptions.path = this.getNormalizedPath(clonedOptions); return clonedOptions; } generateSchema(options) { return this.graphQlFactory.generateSchema(options); } /** * Wraps the `subscribe` function of a `@Subscription()` handler with its * `filter`. This is the only place the filter is applied, and the default * implementation does not apply it: a driver that serves subscriptions must * override this method. */ subscriptionWithFilter(instanceRef, filterFn, createSubscribeContext) { return createSubscribeContext(); } getNormalizedPath(options) { return this.applyGlobalPrefix(options.path, options); } applyGlobalPrefix(path, options) { const prefix = this.applicationConfig?.getGlobalPrefix() ?? ''; const useGlobalPrefix = prefix && options.useGlobalPrefix; const normalizedPath = normalizeRoutePath(path); return useGlobalPrefix ? normalizeRoutePath(prefix) + normalizedPath : normalizedPath; } } __decorate([ Inject(), __metadata("design:type", HttpAdapterHost) ], AbstractGraphQLDriver.prototype, "httpAdapterHost", void 0); __decorate([ Inject(), __metadata("design:type", ApplicationConfig) ], AbstractGraphQLDriver.prototype, "applicationConfig", void 0); __decorate([ Inject(), __metadata("design:type", GraphQLFactory) ], AbstractGraphQLDriver.prototype, "graphQlFactory", void 0); __decorate([ Inject(), __metadata("design:type", ResolverDecoratorHost) ], AbstractGraphQLDriver.prototype, "resolverDecoratorHost", void 0);