@nestjs/graphql
Version:
Nest - modern, fast, powerful node.js web framework (@graphql)
59 lines (58 loc) • 2.42 kB
JavaScript
import { __decorate, __metadata, __param } from "tslib";
import { Inject, Injectable } from '@nestjs/common';
import { isFunction } from '@nestjs/common/utils/shared.utils.js';
import { ModulesContainer } from '@nestjs/core';
import { GRAPHQL_MODULE_OPTIONS, SCALAR_NAME_METADATA, SCALAR_TYPE_METADATA, } from '../graphql.constants.js';
import { createScalarType } from '../utils/scalar-types.utils.js';
import { BaseExplorerService } from './base-explorer.service.js';
let ScalarsExplorerService = class ScalarsExplorerService extends BaseExplorerService {
constructor(modulesContainer, gqlOptions) {
super();
this.modulesContainer = modulesContainer;
this.gqlOptions = gqlOptions;
}
explore() {
const modules = this.getModules(this.modulesContainer, this.gqlOptions.include || []);
return this.flatMap(modules, (instance) => this.filterSchemaFirstScalar(instance));
}
filterSchemaFirstScalar(wrapper) {
const { instance } = wrapper;
if (!instance) {
return undefined;
}
const scalarName = Reflect.getMetadata(SCALAR_NAME_METADATA, instance.constructor);
if (!scalarName) {
return;
}
return {
[scalarName]: createScalarType(scalarName, instance),
};
}
getScalarsMap() {
const modules = this.getModules(this.modulesContainer, this.gqlOptions.include || []);
return this.flatMap(modules, (instance) => this.filterCodeFirstScalar(instance));
}
filterCodeFirstScalar(wrapper) {
const { instance } = wrapper;
if (!instance) {
return undefined;
}
const scalarNameMetadata = Reflect.getMetadata(SCALAR_NAME_METADATA, instance.constructor);
const scalarTypeMetadata = Reflect.getMetadata(SCALAR_TYPE_METADATA, instance.constructor);
if (!scalarNameMetadata) {
return;
}
const typeRef = (isFunction(scalarTypeMetadata) && scalarTypeMetadata()) ||
instance.constructor;
return {
type: typeRef,
scalar: createScalarType(scalarNameMetadata, instance),
};
}
};
ScalarsExplorerService = __decorate([
Injectable(),
__param(1, Inject(GRAPHQL_MODULE_OPTIONS)),
__metadata("design:paramtypes", [ModulesContainer, Object])
], ScalarsExplorerService);
export { ScalarsExplorerService };