@aws-amplify/graphql-transformer-core
Version:
A framework to transform from GraphQL SDL to AWS CloudFormation.
44 lines • 2.98 kB
JavaScript
;
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
var _ModelFieldMapImpl_fieldMapping, _ModelFieldMapImpl_resolverReferences;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ModelFieldMapImpl = void 0;
const lodash_1 = __importDefault(require("lodash"));
class ModelFieldMapImpl {
constructor() {
_ModelFieldMapImpl_fieldMapping.set(this, []);
_ModelFieldMapImpl_resolverReferences.set(this, []);
this.addMappedField = (entry) => {
const existingEntry = __classPrivateFieldGet(this, _ModelFieldMapImpl_fieldMapping, "f").find(fieldMapEqualsPredicate(entry));
if (existingEntry) {
throw new Error(`Field mapping for [${existingEntry.currentFieldName}] to [${existingEntry.originalFieldName}] already exists. Cannot insert mapping to [${entry.originalFieldName}]`);
}
__classPrivateFieldGet(this, _ModelFieldMapImpl_fieldMapping, "f").push(entry);
return this;
};
this.addResolverReference = (entry) => {
const existingEntry = __classPrivateFieldGet(this, _ModelFieldMapImpl_resolverReferences, "f").find(resolverReferenceEqualsPredicate(entry));
if (!existingEntry) {
__classPrivateFieldGet(this, _ModelFieldMapImpl_resolverReferences, "f").push(entry);
}
else if (existingEntry.isList !== entry.isList) {
throw new Error(`Resolver of type [${existingEntry.typeName}] and field [${existingEntry.fieldName}] already registered with isList set to [${existingEntry.isList}]`);
}
return this;
};
this.getMappedFields = () => lodash_1.default.cloneDeep(__classPrivateFieldGet(this, _ModelFieldMapImpl_fieldMapping, "f"));
this.getResolverReferences = () => lodash_1.default.cloneDeep(__classPrivateFieldGet(this, _ModelFieldMapImpl_resolverReferences, "f"));
}
}
exports.ModelFieldMapImpl = ModelFieldMapImpl;
_ModelFieldMapImpl_fieldMapping = new WeakMap(), _ModelFieldMapImpl_resolverReferences = new WeakMap();
const fieldMapEqualsPredicate = (compareTo) => (entry) => compareTo.currentFieldName === entry.currentFieldName;
const resolverReferenceEqualsPredicate = (compareTo) => (entry) => compareTo.typeName === entry.typeName && compareTo.fieldName === entry.fieldName;
//# sourceMappingURL=model-field-map.js.map