UNPKG

@neo4j/graphql

Version:

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

43 lines 1.93 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. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.addGlobalNodeFields = addGlobalNodeFields; const graphql_relay_1 = require("graphql-relay"); const global_node_1 = require("./resolvers/query/global-node"); const ConcreteEntityAdapter_1 = require("../schema-model/entity/model-adapters/ConcreteEntityAdapter"); // returns true if globalNodeFields added or false if not function addGlobalNodeFields(nodes, composer, concreteEntities) { const globalNodes = nodes.filter((n) => n.isGlobalNode); const globalEntities = concreteEntities.map((e) => new ConcreteEntityAdapter_1.ConcreteEntityAdapter(e)).filter((e) => e.isGlobalNode()); if (globalNodes.length === 0) return false; const fetchById = (id, context, info) => { const resolver = (0, global_node_1.globalNodeResolver)({ entities: globalEntities }); return resolver.resolve(null, { id }, context, info); }; const resolveType = (obj) => obj.__resolveType; const { nodeInterface, nodeField } = (0, graphql_relay_1.nodeDefinitions)(fetchById, resolveType); composer.createInterfaceTC(nodeInterface); composer.Query.addFields({ node: nodeField, }); return true; } //# sourceMappingURL=create-global-nodes.js.map