@pothos/core
Version:
Pothos (formerly GiraphQL) is a plugin based schema builder for creating code-first GraphQL schemas in typescript
64 lines (63 loc) • 1.99 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "UnionRef", {
enumerable: true,
get: function() {
return UnionRef;
}
});
const _typeparams = require("../types/type-params");
const _base = require("./base");
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;
}
let _outputShapeKey = _typeparams.outputShapeKey, _parentShapeKey = _typeparams.parentShapeKey;
class UnionRef extends _base.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