@pothos/core
Version:
Pothos (formerly GiraphQL) is a plugin based schema builder for creating code-first GraphQL schemas in typescript
56 lines (55 loc) • 1.76 kB
JavaScript
function _define_property(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
}
else {
obj[key] = value;
}
return obj;
}
import { outputShapeKey, parentShapeKey } from '../types/type-params.js';
import { BaseTypeRef } from './base.js';
let _outputShapeKey = outputShapeKey, _parentShapeKey = parentShapeKey;
export class UnionRef extends BaseTypeRef {
addTypes(types) {
if (Array.isArray(types) && types.length === 0) {
return;
}
if (this.preparedForBuild) {
this.updateConfig((cfg) => ({
...cfg,
types: [
...cfg.types,
...typeof types === "function" ? types() : types
]
}));
}
else {
this.types.push(() => Array.isArray(types) ? types : types());
}
}
prepareForBuild() {
if (this.preparedForBuild) {
return;
}
super.prepareForBuild();
if (this.types.length > 0) {
this.updateConfig((cfg) => ({
...cfg,
types: [
...cfg.types,
...this.types.flatMap((types) => types())
]
}));
}
}
constructor(name, config) {
super("Union", name, config), _define_property(this, "kind", "Union"), _define_property(this, "$inferType", void 0), _define_property(this, _outputShapeKey, void 0), _define_property(this, _parentShapeKey, void 0), _define_property(this, "types", []);
}
}
//# sourceMappingURL=union.js.map