UNPKG

@neo4j/graphql

Version:

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

102 lines 4.14 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. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.UNSUPPORTED_REASON_CONNECT = exports.UNSUPPORTED_REASON_POPULATED_BY = exports.UNSUPPORTED_REASON_ABSTRACT_TYPES = exports.UNSUPPORTED_REASON_SUBSCRIPTION = void 0; exports.isUnwindCreateSupported = isUnwindCreateSupported; const utils_1 = require("../../../../utils/utils"); const is_concrete_entity_1 = require("../../utils/is-concrete-entity"); exports.UNSUPPORTED_REASON_SUBSCRIPTION = "Unwind create optimization does not yet support subscriptions"; exports.UNSUPPORTED_REASON_ABSTRACT_TYPES = "Abstract types are not yet supported"; exports.UNSUPPORTED_REASON_POPULATED_BY = "Annotation: populatedBy is not yet supported"; exports.UNSUPPORTED_REASON_CONNECT = "Operation: connect is not yet supported"; const SUPPORTED = { isSupported: true, reason: "", }; function isUnwindCreateSupported(entityAdapter, createArgs, context) { const isConcreteEntity = checkIsConcreteEntity(entityAdapter); if (!isConcreteEntity.isSupported) { return isConcreteEntity; } (0, is_concrete_entity_1.assertIsConcreteEntity)(entityAdapter); const unsupportedAnnotation = checkUnsupportedAnnotations(entityAdapter); if (!unsupportedAnnotation.isSupported) { return unsupportedAnnotation; } for (let createArg of createArgs) { if (createArg["node"]) { // top level path does not contains node, apart from that the parsing will be the same. createArg = createArg["node"]; } const entries = Object.entries(createArg); for (const [key, value] of entries) { const relationship = entityAdapter.relationships.get(key); if (relationship) { const isOperationSupported = checkOperation(value); if (!isOperationSupported.isSupported) { return isOperationSupported; } const unsupportedAnnotation = checkUnsupportedAnnotations(relationship); if (!unsupportedAnnotation.isSupported) { return unsupportedAnnotation; } const target = relationship.target; const isNestedSupported = isUnwindCreateSupported(target, (0, utils_1.asArray)(value.create), context); if (!isNestedSupported.isSupported) { return isNestedSupported; } } } } return { isSupported: true, reason: "", }; } function checkIsConcreteEntity(entityAdapter) { if (!(0, is_concrete_entity_1.isConcreteEntity)(entityAdapter)) { return { isSupported: false, reason: exports.UNSUPPORTED_REASON_ABSTRACT_TYPES, }; } return SUPPORTED; } function checkUnsupportedAnnotations(concreteEntity) { for (const attribute of concreteEntity.attributes.values()) { if (attribute.annotations.populatedBy && attribute.annotations.populatedBy.operations.includes("CREATE")) { return { isSupported: false, reason: exports.UNSUPPORTED_REASON_POPULATED_BY, }; } } return SUPPORTED; } function checkOperation(args) { if (args.connect) { return { isSupported: false, reason: exports.UNSUPPORTED_REASON_CONNECT, }; } return SUPPORTED; } //# sourceMappingURL=is-unwind-create-supported.js.map