UNPKG

1.86 kBJavaScriptView Raw
1"use strict";
2/**
3 * The API surface of this module has been heavily inspired by the "type-graphql" library (https://github.com/MichalLytek/type-graphql), originally designed & released by Michal Lytek.
4 * In the v6 major release of NestJS, we introduced the code-first approach as a compatibility layer between this package and the `@nestjs/graphql` module.
5 * Eventually, our team decided to reimplement all the features from scratch due to a lack of flexibility.
6 * To avoid numerous breaking changes, the public API is backward-compatible and may resemble "type-graphql".
7 */
8Object.defineProperty(exports, "__esModule", { value: true });
9exports.InputType = void 0;
10const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
11const class_type_enum_1 = require("../enums/class-type.enum");
12const lazy_metadata_storage_1 = require("../schema-builder/storages/lazy-metadata.storage");
13const type_metadata_storage_1 = require("../schema-builder/storages/type-metadata.storage");
14const add_class_type_metadata_util_1 = require("../utils/add-class-type-metadata.util");
15/**
16 * Decorator that marks a class as a GraphQL input type.
17 */
18function InputType(nameOrOptions, inputTypeOptions) {
19 const [name, options = {}] = (0, shared_utils_1.isString)(nameOrOptions)
20 ? [nameOrOptions, inputTypeOptions]
21 : [undefined, nameOrOptions];
22 return (target) => {
23 const metadata = {
24 target,
25 name: name || target.name,
26 description: options.description,
27 isAbstract: options.isAbstract,
28 };
29 lazy_metadata_storage_1.LazyMetadataStorage.store(() => type_metadata_storage_1.TypeMetadataStorage.addInputTypeMetadata(metadata));
30 (0, add_class_type_metadata_util_1.addClassTypeMetadata)(target, class_type_enum_1.ClassType.INPUT);
31 };
32}
33exports.InputType = InputType;