@pothos/core
Version:
Pothos (formerly GiraphQL) is a plugin based schema builder for creating code-first GraphQL schemas in typescript
70 lines (69 loc) • 2.06 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 { PothosSchemaError } from '../errors.js';
export class BaseTypeRef {
toString() {
return `${this.kind}Ref<${this.name}>`;
}
associate(ref) {
if (this.association && typeof this.associate !== "string") {
throw new PothosSchemaError(`${this} is already associated with ${this.association}`);
}
this.association = ref;
}
onConfig(cb) {
this.configCallbacks.add(cb);
if (this.currentConfig) {
cb(this.currentConfig);
}
}
updateConfig(config) {
if (typeof config === "function") {
this.onceOnConfig((oldConfig) => {
this.updateConfig(config(oldConfig));
});
return;
}
this.currentConfig = config;
for (const cb of this.configCallbacks) {
if (this.currentConfig !== config) {
break;
}
cb(config);
}
}
prepareForBuild() {
this.preparedForBuild = true;
}
onceOnConfig(cb) {
const callback = (config) => {
this.configCallbacks.delete(callback);
cb(config);
};
this.onConfig(callback);
}
constructor(kind, name, config) {
_define_property(this, "kind", void 0);
_define_property(this, "name", void 0);
_define_property(this, "association", null);
_define_property(this, "configCallbacks", new Set());
_define_property(this, "preparedForBuild", false);
_define_property(this, "currentConfig", void 0);
this.kind = kind;
this.name = name;
this.currentConfig = config !== null && config !== void 0 ? config : null;
}
}
//# sourceMappingURL=base.js.map