UNPKG

@neo4j/graphql

Version:

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

101 lines 4.82 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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.createConnectionWherePropertyOperation = createConnectionWherePropertyOperation; const cypher_builder_1 = __importDefault(require("@neo4j/cypher-builder")); const get_entity_adapter_from_node_1 = require("../../../utils/get-entity-adapter-from-node"); const utils_1 = require("../../../utils/utils"); const logical_operators_1 = require("../../utils/logical-operators"); const create_where_predicate_1 = require("../create-where-predicate"); function createConnectionWherePropertyOperation({ context, whereInput, edgeRef, targetNode, node, edge, useExistExpr = true, checkParameterExistence, }) { const preComputedSubqueriesResult = []; const params = []; Object.entries(whereInput).forEach(([key, value]) => { if ((0, logical_operators_1.isLogicalOperator)(key)) { const subOperations = []; (0, utils_1.asArray)(value).forEach((input) => { const { predicate, preComputedSubqueries } = createConnectionWherePropertyOperation({ context, whereInput: input, edgeRef, targetNode, node, edge, useExistExpr, checkParameterExistence, }); subOperations.push(predicate); if (preComputedSubqueries && !preComputedSubqueries.empty) preComputedSubqueriesResult.push(preComputedSubqueries); }); const logicalPredicate = (0, logical_operators_1.getLogicalPredicate)(key, (0, utils_1.filterTruthy)(subOperations)); params.push(logicalPredicate); return; } if (key.startsWith("edge")) { const entity = context.schemaModel.getConcreteEntityAdapter(edge.source); if (!entity) { throw new Error(`Transpilation error: entity not found: ${edge.source}`); } const relationshipAdapter = [...entity.relationships.values()].find((r) => r.operations.relationshipFieldTypename === edge.name); if (!relationshipAdapter) { throw new Error(`No relationship found for ${edge.name}`); } const { predicate: result, preComputedSubqueries } = (0, create_where_predicate_1.createWhereEdgePredicate)({ targetElement: targetNode, relationshipVariable: edgeRef, relationship: relationshipAdapter, context, whereInput: value, }); params.push(result); if (preComputedSubqueries && !preComputedSubqueries.empty) { preComputedSubqueriesResult.push(preComputedSubqueries); } return; } if (key.startsWith("node") || key.startsWith(node.name)) { // TODO: improve nodeOn properties generation const nestedProperties = { ...value }; const entity = (0, get_entity_adapter_from_node_1.getEntityAdapterFromNode)(node, context); const { predicate: result, preComputedSubqueries } = (0, create_where_predicate_1.createWhereNodePredicate)({ entity, context, whereInput: nestedProperties, targetElement: targetNode, }); // NOTE: _NOT is handled by the size()=0 params.push(result); if (preComputedSubqueries && !preComputedSubqueries.empty) preComputedSubqueriesResult.push(preComputedSubqueries); return; } }); return { predicate: cypher_builder_1.default.and(...(0, utils_1.filterTruthy)(params)), preComputedSubqueries: preComputedSubqueriesResult.length ? cypher_builder_1.default.utils.concat(...preComputedSubqueriesResult) : undefined, }; } //# sourceMappingURL=create-connection-operation.js.map