@neo4j/graphql
Version:
A GraphQL to Cypher query execution layer for Neo4j and JavaScript GraphQL implementations
79 lines • 3.42 kB
JavaScript
/*
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.InterfaceEntity = void 0;
const pluralize_1 = require("pluralize");
const typescript_memoize_1 = require("typescript-memoize");
const classes_1 = require("../../classes");
class InterfaceEntity {
constructor({ name, description, concreteEntities, attributes = [], annotations = {}, relationshipDeclarations = [], }) {
this.attributes = new Map();
this.relationshipDeclarations = new Map();
this.name = name;
this.description = description;
this.concreteEntities = concreteEntities;
this.annotations = annotations;
for (const attribute of attributes) {
this.addAttribute(attribute);
}
for (const relationshipDeclaration of relationshipDeclarations) {
this.addRelationshipDeclaration(relationshipDeclaration);
}
}
isConcreteEntity() {
return false;
}
isCompositeEntity() {
return true;
}
addAttribute(attribute) {
if (this.attributes.has(attribute.name)) {
throw new classes_1.Neo4jGraphQLSchemaValidationError(`Attribute ${attribute.name} already exists in ${this.name}`);
}
this.attributes.set(attribute.name, attribute);
}
addRelationshipDeclaration(relationshipDeclaration) {
if (this.relationshipDeclarations.has(relationshipDeclaration.name)) {
throw new classes_1.Neo4jGraphQLSchemaValidationError(`Attribute ${relationshipDeclaration.name} already exists in ${this.name}`);
}
this.relationshipDeclarations.set(relationshipDeclaration.name, relationshipDeclaration);
}
findAttribute(name) {
return this.attributes.get(name);
}
// Duplicate in EntityAdapters
get plural() {
if (this.annotations.plural) {
return (0, pluralize_1.singular)(this.annotations.plural.value);
}
return (0, pluralize_1.plural)(this.name);
}
}
exports.InterfaceEntity = InterfaceEntity;
__decorate([
(0, typescript_memoize_1.Memoize)()
], InterfaceEntity.prototype, "plural", null);
//# sourceMappingURL=InterfaceEntity.js.map
;