UNPKG

@neo4j/graphql

Version:

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

84 lines 3.95 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.createWhereNodePredicate = createWhereNodePredicate; exports.createWhereEdgePredicate = createWhereEdgePredicate; const cypher_builder_1 = __importDefault(require("@neo4j/cypher-builder")); const RelationshipAdapter_1 = require("../../schema-model/relationship/model-adapters/RelationshipAdapter"); const QueryASTContext_1 = require("../queryAST/ast/QueryASTContext"); const QueryASTFactory_1 = require("../queryAST/factory/QueryASTFactory"); const is_interface_entity_1 = require("../queryAST/utils/is-interface-entity"); const wrap_subquery_in_calls_1 = require("../queryAST/utils/wrap-subquery-in-calls"); function createWherePredicate({ factory, queryASTContext, entityOrRel, whereInput, targetElement, targetEntity, }) { const filters = []; if (entityOrRel instanceof RelationshipAdapter_1.RelationshipAdapter) { filters.push(...factory.filterFactory.createEdgeFilters(entityOrRel, whereInput)); } else if ((0, is_interface_entity_1.isInterfaceEntity)(entityOrRel)) { filters.push(...factory.filterFactory.createInterfaceNodeFilters({ entity: entityOrRel, targetEntity, whereFields: whereInput, })); } else { filters.push(...factory.filterFactory.createNodeFilters(entityOrRel, whereInput)); } const subqueries = (0, wrap_subquery_in_calls_1.wrapSubqueriesInCypherCalls)(queryASTContext, filters, [targetElement]); const predicates = filters.map((f) => f.getPredicate(queryASTContext)); const extraSelections = filters.flatMap((f) => f.getSelection(queryASTContext)); const preComputedSubqueries = [...extraSelections, ...subqueries]; return { predicate: cypher_builder_1.default.and(...predicates), preComputedSubqueries: cypher_builder_1.default.utils.concat(...preComputedSubqueries), }; } function createWhereNodePredicate({ targetElement, whereInput, context, entity, targetEntity, }) { const factory = new QueryASTFactory_1.QueryASTFactory(context.schemaModel); const queryASTEnv = new QueryASTContext_1.QueryASTEnv(); const queryASTContext = new QueryASTContext_1.QueryASTContext({ target: targetElement, env: queryASTEnv, neo4jGraphQLContext: context, }); return createWherePredicate({ factory, queryASTContext, entityOrRel: entity, whereInput, targetElement, targetEntity, }); } function createWhereEdgePredicate({ targetElement, relationshipVariable, whereInput, context, relationship, }) { const factory = new QueryASTFactory_1.QueryASTFactory(context.schemaModel); const queryASTEnv = new QueryASTContext_1.QueryASTEnv(); const queryASTContext = new QueryASTContext_1.QueryASTContext({ target: targetElement, relationship: relationshipVariable, env: queryASTEnv, neo4jGraphQLContext: context, }); return createWherePredicate({ factory, queryASTContext, entityOrRel: relationship, whereInput, targetElement }); } //# sourceMappingURL=create-where-predicate.js.map