UNPKG

@neo4j/graphql

Version:

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

99 lines 4.02 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.translateTopLevelMatch = translateTopLevelMatch; const cypher_builder_1 = __importDefault(require("@neo4j/cypher-builder")); const get_entity_adapter_from_node_1 = require("../utils/get-entity-adapter-from-node"); const create_authorization_before_predicate_1 = require("./authorization/create-authorization-before-predicate"); const build_clause_1 = require("./utils/build-clause"); const create_where_predicate_1 = require("./where/create-where-predicate"); function translateTopLevelMatch({ matchNode, matchPattern, node, context, operation, where, }) { const { matchClause, preComputedWhereFieldSubqueries, whereClause } = createMatchClause({ matchNode, matchPattern, node, context, operation, where, }); return (0, build_clause_1.buildClause)(cypher_builder_1.default.utils.concat(matchClause, preComputedWhereFieldSubqueries, whereClause), { context }); } function createMatchClause({ matchNode, matchPattern, node, context, operation, where, }) { const matchClause = new cypher_builder_1.default.Match(matchPattern); const whereOperators = []; let whereClause; const authorizationPredicateReturn = (0, create_authorization_before_predicate_1.createAuthorizationBeforePredicate)({ context, nodes: [ { variable: matchNode, node, }, ], operations: [operation], }); if (authorizationPredicateReturn?.predicate) { whereClause = new cypher_builder_1.default.With("*"); } else { whereClause = matchClause; } let preComputedWhereFieldSubqueries; if (where) { const entity = (0, get_entity_adapter_from_node_1.getEntityAdapterFromNode)(node, context); const { predicate: whereOp, preComputedSubqueries } = (0, create_where_predicate_1.createWhereNodePredicate)({ targetElement: matchNode, whereInput: where, context, entity, }); preComputedWhereFieldSubqueries = preComputedSubqueries; if (preComputedWhereFieldSubqueries && !preComputedWhereFieldSubqueries.empty) { whereClause = new cypher_builder_1.default.With("*"); } if (whereOp) whereClause.where(whereOp); } if (whereOperators && whereOperators.length) { const andChecks = cypher_builder_1.default.and(...whereOperators); whereClause.where(andChecks); } if (authorizationPredicateReturn) { const { predicate, preComputedSubqueries } = authorizationPredicateReturn; if (predicate) { whereClause.where(predicate); } if (preComputedSubqueries && !preComputedSubqueries.empty) { preComputedWhereFieldSubqueries = cypher_builder_1.default.utils.concat(preComputedWhereFieldSubqueries, preComputedSubqueries); } } if (matchClause === whereClause) { whereClause = undefined; } return { matchClause, preComputedWhereFieldSubqueries, whereClause, }; } //# sourceMappingURL=translate-top-level-match.js.map