UNPKG

@neo4j/graphql

Version:

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

75 lines 3.1 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.findResolver = findResolver; const graphql_1 = require("graphql"); const UnionEntityAdapter_1 = require("../../../schema-model/entity/model-adapters/UnionEntityAdapter"); const translate_1 = require("../../../translate"); const is_concrete_entity_1 = require("../../../translate/queryAST/utils/is-concrete-entity"); const utils_1 = require("../../../utils"); const get_neo4j_resolve_tree_1 = __importDefault(require("../../../utils/get-neo4j-resolve-tree")); const sort_and_options_input_1 = require("../../generation/sort-and-options-input"); function findResolver({ entityAdapter, composer, isLimitRequired, }) { async function resolve(_root, args, context, info) { const resolveTree = (0, get_neo4j_resolve_tree_1.default)(info, { args }); context.resolveTree = resolveTree; // for composite entities we don't use "this" as varName but we use an autogenerated variable let varName; if ((0, is_concrete_entity_1.isConcreteEntity)(entityAdapter)) { varName = "this"; } const { cypher, params } = (0, translate_1.translateRead)({ context: context, entityAdapter, varName, }); const executeResult = await (0, utils_1.execute)({ cypher, params, defaultAccessMode: "READ", context, info, }); return executeResult.records.map((x) => x.this); } const extraArgs = {}; const whereArgumentType = entityAdapter.operations.whereInputTypeName; const args = { where: whereArgumentType, limit: isLimitRequired ? new graphql_1.GraphQLNonNull(graphql_1.GraphQLInt) : graphql_1.GraphQLInt, offset: graphql_1.GraphQLInt, ...extraArgs, }; if (!(entityAdapter instanceof UnionEntityAdapter_1.UnionEntityAdapter)) { const sortConfig = (0, sort_and_options_input_1.makeSortInput)({ entityAdapter, userDefinedFieldDirectives: new Map(), composer }); if (sortConfig) { args["sort"] = sortConfig.NonNull.List; } } return { type: `[${entityAdapter.name}!]!`, resolve, args, }; } //# sourceMappingURL=read.js.map