UNPKG

@neo4j/graphql

Version:

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

70 lines 3.49 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.CypherEntityOperation = void 0; const cypher_builder_1 = __importDefault(require("@neo4j/cypher-builder")); const ReadOperation_1 = require("./ReadOperation"); class CypherEntityOperation extends ReadOperation_1.ReadOperation { constructor({ cypherAttributeField, target, relationship, selection, }) { super({ target, relationship, selection }); this.cypherAttributeField = cypherAttributeField; } transpile(context) { // eslint-disable-next-line prefer-const let { selection: matchClause, nestedContext } = this.selection.apply(context); const fieldSubqueries = cypher_builder_1.default.utils.concat(...this.getFieldsSubqueries(nestedContext), ...this.getCypherFieldsSubqueries(nestedContext)); const authFilterSubqueries = this.getAuthFilterSubqueries(nestedContext).map((sq) => new cypher_builder_1.default.Call(sq, [nestedContext.target])); const authPredicates = this.getAuthFilterPredicate(nestedContext); const validations = this.getValidations(nestedContext); const authClauses = authPredicates.length || validations.length ? [...authFilterSubqueries, new cypher_builder_1.default.With("*").where(cypher_builder_1.default.and(...authPredicates)), ...validations] : []; const ret = this.getReturnClause(nestedContext, context.returnVariable); const extraMatches = this.getChildren().flatMap((f) => f.getSelection(nestedContext)); const clause = cypher_builder_1.default.utils.concat(matchClause, ...extraMatches, fieldSubqueries, ...authClauses, ret); return { clauses: [clause], projectionExpr: context.returnVariable, }; } getReturnClause(context, returnVariable) { const projection = this.getProjectionMap(context); let returnExpr; if (context.shouldCollect) { returnExpr = cypher_builder_1.default.collect(context.target); } else { returnExpr = context.target; } if (context.shouldCollect && !this.cypherAttributeField.typeHelper.isList()) { returnExpr = cypher_builder_1.default.head(returnExpr); } const withClause = new cypher_builder_1.default.With([projection, context.target]); if (this.sortFields.length > 0 || this.pagination) { this.addSortToClause(context, context.target, withClause); } return withClause.return([returnExpr, returnVariable]); } } exports.CypherEntityOperation = CypherEntityOperation; //# sourceMappingURL=CypherEntityOperation.js.map