@pothos/core
Version:
Pothos (formerly GiraphQL) is a plugin based schema builder for creating code-first GraphQL schemas in typescript
79 lines (78 loc) • 2.25 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "BaseTypeRef", {
enumerable: true,
get: function() {
return BaseTypeRef;
}
});
const _errors = require("../errors");
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;
}
class BaseTypeRef {
toString() {
return `${this.kind}Ref<${this.name}>`;
}
associate(ref) {
if (this.association && typeof this.associate !== 'string') {
throw new _errors.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