UNPKG

@neo4j/graphql

Version:

A GraphQL to Cypher query execution layer for Neo4j and JavaScript GraphQL implementations

93 lines 3.86 kB
"use strict"; /* * 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.ConcreteEntity = void 0; const typescript_memoize_1 = require("typescript-memoize"); const classes_1 = require("../../classes"); const sets_are_equal_1 = require("../../utils/sets-are-equal"); const string_manipulation_1 = require("../utils/string-manipulation"); class ConcreteEntity { constructor({ name, description, labels, attributes = [], annotations = {}, relationships = [], compositeEntities = [], }) { this.attributes = new Map(); this.relationships = new Map(); this.compositeEntities = []; // The composite entities that this entity is a part of this.name = name; this.description = description; this.labels = new Set(labels); this.annotations = annotations; for (const attribute of attributes) { this.addAttribute(attribute); } for (const relationship of relationships) { this.addRelationship(relationship); } for (const entity of compositeEntities) { this.addCompositeEntities(entity); } } isConcreteEntity() { return true; } isCompositeEntity() { return false; } matchLabels(labels) { return (0, sets_are_equal_1.setsAreEqual)(new Set(labels), this.labels); } 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); } addRelationship(relationship) { if (this.relationships.has(relationship.name)) { throw new classes_1.Neo4jGraphQLSchemaValidationError(`Attribute ${relationship.name} already exists in ${this.name}`); } this.relationships.set(relationship.name, relationship); } addCompositeEntities(entity) { this.compositeEntities.push(entity); } findAttribute(name) { return this.attributes.get(name); } findRelationship(name) { return this.relationships.get(name); } // Duplicate in EntityAdapters get plural() { if (this.annotations.plural) { return (0, string_manipulation_1.singular)(this.annotations.plural.value); } return (0, string_manipulation_1.plural)(this.name); } } exports.ConcreteEntity = ConcreteEntity; __decorate([ (0, typescript_memoize_1.Memoize)() ], ConcreteEntity.prototype, "plural", null); //# sourceMappingURL=ConcreteEntity.js.map