UNPKG

1.89 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.AbstractGraphQLDriver = void 0;
4const tslib_1 = require("tslib");
5const common_1 = require("@nestjs/common");
6const core_1 = require("@nestjs/core");
7const graphql_factory_1 = require("../graphql.factory");
8const utils_1 = require("../utils");
9class AbstractGraphQLDriver {
10 async mergeDefaultOptions(options, defaults = {
11 path: '/graphql',
12 fieldResolverEnhancers: [],
13 }) {
14 const clonedOptions = {
15 ...defaults,
16 ...options,
17 };
18 clonedOptions.path =
19 this.getNormalizedPath(clonedOptions);
20 return clonedOptions;
21 }
22 generateSchema(options) {
23 return this.graphQlFactory.generateSchema(options);
24 }
25 subscriptionWithFilter(instanceRef, filterFn, createSubscribeContext) {
26 return createSubscribeContext();
27 }
28 getNormalizedPath(options) {
29 const prefix = this.applicationConfig?.getGlobalPrefix() ?? '';
30 const useGlobalPrefix = prefix && options.useGlobalPrefix;
31 const gqlOptionsPath = (0, utils_1.normalizeRoutePath)(options.path);
32 return useGlobalPrefix
33 ? (0, utils_1.normalizeRoutePath)(prefix) + gqlOptionsPath
34 : gqlOptionsPath;
35 }
36}
37exports.AbstractGraphQLDriver = AbstractGraphQLDriver;
38tslib_1.__decorate([
39 (0, common_1.Inject)(),
40 tslib_1.__metadata("design:type", core_1.HttpAdapterHost)
41], AbstractGraphQLDriver.prototype, "httpAdapterHost", void 0);
42tslib_1.__decorate([
43 (0, common_1.Inject)(),
44 tslib_1.__metadata("design:type", core_1.ApplicationConfig)
45], AbstractGraphQLDriver.prototype, "applicationConfig", void 0);
46tslib_1.__decorate([
47 (0, common_1.Inject)(),
48 tslib_1.__metadata("design:type", graphql_factory_1.GraphQLFactory)
49], AbstractGraphQLDriver.prototype, "graphQlFactory", void 0);