@nestjs/graphql
Version:
Nest - modern, fast, powerful node.js web framework (@graphql)
57 lines (56 loc) • 1.99 kB
JavaScript
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);
}
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);