@pothos/plugin-federation
Version:
A Pothos plugin for implementing apollo federation subGraphs
65 lines (64 loc) • 2.79 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 { FieldBuilder, ObjectRef, RootFieldBuilder } from '@pothos/core';
import { addUsedDirectives, keyDirective, mergeDirectives } from './util.js';
export const providesMap = new WeakMap();
export class ExternalEntityRef extends ObjectRef {
implement({ fields, externalFields, directives, ...options }) {
var _options_extensions, _options_extensions_apollo, _options_extensions1;
addUsedDirectives(this.builder, [
'extends',
'key'
]);
this.builder.objectType(this, {
...options,
name: this.name,
directives: mergeDirectives(directives, [
...this.key ? keyDirective(this.key) : [],
{
name: 'extends',
args: {}
}
]),
fields: ()=>({
...externalFields === null || externalFields === void 0 ? void 0 : externalFields(new RootFieldBuilder(this.builder, 'ExternalEntity', 'Object')),
...fields === null || fields === void 0 ? void 0 : fields(new FieldBuilder(this.builder, 'ExtendedEntity', 'Object'))
}),
extensions: {
...options.extensions,
apollo: {
...(_options_extensions = options.extensions) === null || _options_extensions === void 0 ? void 0 : _options_extensions.apollo,
subgraph: {
...(_options_extensions1 = options.extensions) === null || _options_extensions1 === void 0 ? void 0 : (_options_extensions_apollo = _options_extensions1.apollo) === null || _options_extensions_apollo === void 0 ? void 0 : _options_extensions_apollo.subgraph,
resolveReference: this.resolveReference
}
}
}
});
return this;
}
provides(selection) {
const ref = Object.create(this);
providesMap.set(ref, selection);
this.builder.configStore.associateParamWithRef(ref, this);
return ref;
}
constructor(builder, name, { key, resolveReference }){
super(name), _define_property(this, "kind", 'Object'), _define_property(this, "builder", void 0), _define_property(this, "key", void 0), _define_property(this, "resolveReference", void 0);
this.builder = builder;
this.key = key;
this.resolveReference = resolveReference;
}
}
//# sourceMappingURL=external-ref.js.map