UNPKG

@neo4j/graphql

Version:

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

53 lines 1.76 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.deepMerge = deepMerge; /** Merges the provided objects in an array, returning a single object * nullish values are ignored, and an empty array will return an empty object */ function deepMerge(input) { if (input.length === 0) { return {}; } return input.reduce((acc, obj) => { if (!isObject(obj)) { return acc; } return mergeObjects(acc, obj); }, {}); } function mergeObjects(target, source) { const result = { ...target }; for (const key of Object.keys(source)) { const sourceValue = source[key]; const targetValue = target[key]; if (isObject(sourceValue) && isObject(targetValue)) { result[key] = mergeObjects(targetValue, sourceValue); } else if (source[key] !== undefined) { result[key] = source[key]; } } return result; } function isObject(a) { return typeof a === "object" && Boolean(a) && !Array.isArray(a); } //# sourceMappingURL=deep-merge.js.map