1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.ScalarsExplorerService = void 0;
|
4 | const tslib_1 = require("tslib");
|
5 | const common_1 = require("@nestjs/common");
|
6 | const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
|
7 | const core_1 = require("@nestjs/core");
|
8 | const graphql_constants_1 = require("../graphql.constants");
|
9 | const scalar_types_utils_1 = require("../utils/scalar-types.utils");
|
10 | const base_explorer_service_1 = require("./base-explorer.service");
|
11 | let ScalarsExplorerService = class ScalarsExplorerService extends base_explorer_service_1.BaseExplorerService {
|
12 | constructor(modulesContainer, gqlOptions) {
|
13 | super();
|
14 | this.modulesContainer = modulesContainer;
|
15 | this.gqlOptions = gqlOptions;
|
16 | }
|
17 | explore() {
|
18 | const modules = this.getModules(this.modulesContainer, this.gqlOptions.include || []);
|
19 | return this.flatMap(modules, (instance) => this.filterSchemaFirstScalar(instance));
|
20 | }
|
21 | filterSchemaFirstScalar(wrapper) {
|
22 | const { instance } = wrapper;
|
23 | if (!instance) {
|
24 | return undefined;
|
25 | }
|
26 | const scalarName = Reflect.getMetadata(graphql_constants_1.SCALAR_NAME_METADATA, instance.constructor);
|
27 | if (!scalarName) {
|
28 | return;
|
29 | }
|
30 | return {
|
31 | [scalarName]: (0, scalar_types_utils_1.createScalarType)(scalarName, instance),
|
32 | };
|
33 | }
|
34 | getScalarsMap() {
|
35 | const modules = this.getModules(this.modulesContainer, this.gqlOptions.include || []);
|
36 | return this.flatMap(modules, (instance) => this.filterCodeFirstScalar(instance));
|
37 | }
|
38 | filterCodeFirstScalar(wrapper) {
|
39 | const { instance } = wrapper;
|
40 | if (!instance) {
|
41 | return undefined;
|
42 | }
|
43 | const scalarNameMetadata = Reflect.getMetadata(graphql_constants_1.SCALAR_NAME_METADATA, instance.constructor);
|
44 | const scalarTypeMetadata = Reflect.getMetadata(graphql_constants_1.SCALAR_TYPE_METADATA, instance.constructor);
|
45 | if (!scalarNameMetadata) {
|
46 | return;
|
47 | }
|
48 | const typeRef = ((0, shared_utils_1.isFunction)(scalarTypeMetadata) && scalarTypeMetadata()) ||
|
49 | instance.constructor;
|
50 | return {
|
51 | type: typeRef,
|
52 | scalar: (0, scalar_types_utils_1.createScalarType)(scalarNameMetadata, instance),
|
53 | };
|
54 | }
|
55 | };
|
56 | exports.ScalarsExplorerService = ScalarsExplorerService;
|
57 | exports.ScalarsExplorerService = ScalarsExplorerService = tslib_1.__decorate([
|
58 | (0, common_1.Injectable)(),
|
59 | tslib_1.__param(1, (0, common_1.Inject)(graphql_constants_1.GRAPHQL_MODULE_OPTIONS)),
|
60 | tslib_1.__metadata("design:paramtypes", [core_1.ModulesContainer, Object])
|
61 | ], ScalarsExplorerService);
|