UNPKG

1.36 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.createUnionType = void 0;
10const lazy_metadata_storage_1 = require("../schema-builder/storages/lazy-metadata.storage");
11const type_metadata_storage_1 = require("../schema-builder/storages/type-metadata.storage");
12/**
13 * Creates a GraphQL union type composed of types references.
14 * @param options
15 */
16function createUnionType(options) {
17 const { name, description, types, resolveType } = options;
18 const id = Symbol(name);
19 lazy_metadata_storage_1.LazyMetadataStorage.store(() => type_metadata_storage_1.TypeMetadataStorage.addUnionMetadata({
20 id,
21 name,
22 description,
23 typesFn: types,
24 resolveType,
25 }));
26 return id;
27}
28exports.createUnionType = createUnionType;