Skip to content

Conversation

ardatan
Copy link
Owner

@ardatan ardatan commented Mar 7, 2025

Fixes #7011

The following inputs and outputs are corrected;

  • mergeDeep([{a:2} undefined]) - Any nullish values should be ignored so it should return {a:2}
  • mergeDeep([]) - no sources should return undefined
  • mergeDeep([undefined]) - no sources should return undefined

Copy link

changeset-bot bot commented Mar 7, 2025

🦋 Changeset detected

Latest commit: 28b79a3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 26 packages
Name Type
@graphql-tools/utils Patch
@graphql-tools/executor Patch
@graphql-tools/graphql-tag-pluck Patch
@graphql-tools/import Patch
@graphql-tools/links Patch
@graphql-tools/load Patch
@graphql-tools/merge Patch
@graphql-tools/mock Patch
@graphql-tools/node-require Patch
@graphql-tools/relay-operation-optimizer Patch
@graphql-tools/resolvers-composition Patch
@graphql-tools/schema Patch
@graphql-tools/apollo-engine-loader Patch
@graphql-tools/code-file-loader Patch
@graphql-tools/git-loader Patch
@graphql-tools/github-loader Patch
@graphql-tools/graphql-file-loader Patch
@graphql-tools/json-file-loader Patch
@graphql-tools/module-loader Patch
@graphql-tools/url-loader Patch
@graphql-tools/executor-apollo-link Patch
@graphql-tools/executor-envelop Patch
@graphql-tools/executor-legacy-ws Patch
@graphql-tools/executor-urql-exchange Patch
@graphql-tools/executor-yoga Patch
graphql-tools Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@ardatan ardatan marked this pull request as ready for review March 7, 2025 12:03
Copy link
Contributor

coderabbitai bot commented Mar 7, 2025

Warning

Rate limit exceeded

@ardatan has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 5 minutes and 47 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 14365b3 and 28b79a3.

📒 Files selected for processing (3)
  • .changeset/chilly-icons-guess.md (1 hunks)
  • packages/utils/src/mergeDeep.ts (2 hunks)
  • packages/utils/tests/mergeDeep.test.ts (1 hunks)
📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes

    • Improved deep merging behavior to correctly ignore nullish inputs and handle empty arrays, ensuring more reliable results.
  • Tests

    • Added new test cases to validate the updated merging functionality and confirm proper behavior in edge-case scenarios.

Walkthrough

This pull request introduces a patch for the mergeDeep function in the @graphql-tools/utils library, improving its handling of nullish values and empty arrays. The function now returns undefined for empty input arrays and skips over nullish values during the merging process. Additionally, it returns the first source when only one is provided. New test cases have been added to ensure these behaviors are correctly implemented.

Changes

File Path(s) Change Summary
.changeset/chilly-icons-guess.md
packages/utils/src/mergeDeep.ts
Updated mergeDeep to handle nullish values and empty inputs. Added checks for empty sources (returning undefined) and single element sources (returning the element directly), and ensured nullish values are skipped during merging.
packages/utils/tests/mergeDeep.test.ts Introduced three new test cases to verify that mergeDeep filters out nullish values, merges non-empty objects, and returns undefined for an empty sources array.

Sequence Diagram(s)

sequenceDiagram
    participant C as Caller
    participant M as mergeDeep Function
    participant S as Source Item

    C->>M: Call mergeDeep(sources)
    alt sources array is empty
        M-->>C: Return undefined
    else sources length is one
        M-->>C: Return the single source
    else
        loop For each source in sources
            alt Source is nullish
                M->>M: Skip this source
            else
                M->>M: Merge source into result
            end
        end
        M-->>C: Return merged result
    end
Loading

Poem

I'm a rabbit hopping through the code,
Skipping over bugs along my winding road.
I fixed mergeDeep with a nimble, clever twist,
Nullish values now fade into a mist.
With tests that crunch like carrots at night,
I celebrate our patch with pure delight! 🥕✨

✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-merge-deepo

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@theguild-bot
Copy link
Collaborator

theguild-bot commented Mar 7, 2025

🚀 Snapshot Release (alpha)

The latest changes of this PR are available as alpha on npm (based on the declared changesets):

Package Version Info
@graphql-tools/executor 1.4.5-alpha-20250307121300-14365b34ed1b50dd48041446ce0a72986ae45a1c npm ↗︎ unpkg ↗︎
@graphql-tools/executor-apollo-link 1.0.18-alpha-20250307121300-14365b34ed1b50dd48041446ce0a72986ae45a1c npm ↗︎ unpkg ↗︎
@graphql-tools/executor-envelop 3.0.26-alpha-20250307121300-14365b34ed1b50dd48041446ce0a72986ae45a1c npm ↗︎ unpkg ↗︎
@graphql-tools/executor-legacy-ws 1.1.16-alpha-20250307121300-14365b34ed1b50dd48041446ce0a72986ae45a1c npm ↗︎ unpkg ↗︎
@graphql-tools/executor-urql-exchange 1.0.18-alpha-20250307121300-14365b34ed1b50dd48041446ce0a72986ae45a1c npm ↗︎ unpkg ↗︎
@graphql-tools/executor-yoga 3.0.26-alpha-20250307121300-14365b34ed1b50dd48041446ce0a72986ae45a1c npm ↗︎ unpkg ↗︎
@graphql-tools/graphql-tag-pluck 8.3.18-alpha-20250307121300-14365b34ed1b50dd48041446ce0a72986ae45a1c npm ↗︎ unpkg ↗︎
graphql-tools 9.0.17-alpha-20250307121300-14365b34ed1b50dd48041446ce0a72986ae45a1c npm ↗︎ unpkg ↗︎
@graphql-tools/import 7.0.17-alpha-20250307121300-14365b34ed1b50dd48041446ce0a72986ae45a1c npm ↗︎ unpkg ↗︎
@graphql-tools/links 9.0.26-alpha-20250307121300-14365b34ed1b50dd48041446ce0a72986ae45a1c npm ↗︎ unpkg ↗︎
@graphql-tools/load 8.0.18-alpha-20250307121300-14365b34ed1b50dd48041446ce0a72986ae45a1c npm ↗︎ unpkg ↗︎
@graphql-tools/apollo-engine-loader 8.0.19-alpha-20250307121300-14365b34ed1b50dd48041446ce0a72986ae45a1c npm ↗︎ unpkg ↗︎
@graphql-tools/code-file-loader 8.1.19-alpha-20250307121300-14365b34ed1b50dd48041446ce0a72986ae45a1c npm ↗︎ unpkg ↗︎
@graphql-tools/git-loader 8.0.23-alpha-20250307121300-14365b34ed1b50dd48041446ce0a72986ae45a1c npm ↗︎ unpkg ↗︎
@graphql-tools/github-loader 8.0.19-alpha-20250307121300-14365b34ed1b50dd48041446ce0a72986ae45a1c npm ↗︎ unpkg ↗︎
@graphql-tools/graphql-file-loader 8.0.18-alpha-20250307121300-14365b34ed1b50dd48041446ce0a72986ae45a1c npm ↗︎ unpkg ↗︎
@graphql-tools/json-file-loader 8.0.17-alpha-20250307121300-14365b34ed1b50dd48041446ce0a72986ae45a1c npm ↗︎ unpkg ↗︎
@graphql-tools/module-loader 8.0.17-alpha-20250307121300-14365b34ed1b50dd48041446ce0a72986ae45a1c npm ↗︎ unpkg ↗︎
@graphql-tools/url-loader 8.0.30-alpha-20250307121300-14365b34ed1b50dd48041446ce0a72986ae45a1c npm ↗︎ unpkg ↗︎
@graphql-tools/merge 9.0.23-alpha-20250307121300-14365b34ed1b50dd48041446ce0a72986ae45a1c npm ↗︎ unpkg ↗︎
@graphql-tools/mock 9.0.21-alpha-20250307121300-14365b34ed1b50dd48041446ce0a72986ae45a1c npm ↗︎ unpkg ↗︎
@graphql-tools/node-require 7.0.19-alpha-20250307121300-14365b34ed1b50dd48041446ce0a72986ae45a1c npm ↗︎ unpkg ↗︎
@graphql-tools/relay-operation-optimizer 7.0.18-alpha-20250307121300-14365b34ed1b50dd48041446ce0a72986ae45a1c npm ↗︎ unpkg ↗︎
@graphql-tools/resolvers-composition 7.0.17-alpha-20250307121300-14365b34ed1b50dd48041446ce0a72986ae45a1c npm ↗︎ unpkg ↗︎
@graphql-tools/schema 10.0.22-alpha-20250307121300-14365b34ed1b50dd48041446ce0a72986ae45a1c npm ↗︎ unpkg ↗︎
@graphql-tools/utils 10.8.5-alpha-20250307121300-14365b34ed1b50dd48041446ce0a72986ae45a1c npm ↗︎ unpkg ↗︎

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/utils/tests/mergeDeep.test.ts (1)

76-86: Consider adding a test for array with only undefined values

The current tests cover empty arrays and arrays with some undefined values, but there's no explicit test for mergeDeep([undefined]) which is mentioned in the changeset. Adding such a test would ensure complete coverage of the scenarios described in the changeset.

  it('returns undefined when an empty sources array passed', () => {
    expect(mergeDeep([])).toEqual(undefined);
  });
+
+ it('returns undefined when array contains only undefined values', () => {
+   expect(mergeDeep([undefined])).toEqual(undefined);
+   expect(mergeDeep([undefined, null, undefined])).toEqual(undefined);
+ });
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ff11a77 and a82ff87.

📒 Files selected for processing (3)
  • .changeset/chilly-icons-guess.md (1 hunks)
  • packages/utils/src/mergeDeep.ts (2 hunks)
  • packages/utils/tests/mergeDeep.test.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (13)
  • GitHub Check: Unit Test on Node 18 (windows-latest) and GraphQL v16
  • GitHub Check: Unit Test on Node 23 (ubuntu-latest) and GraphQL v16
  • GitHub Check: Unit Test on Node 23 (ubuntu-latest) and GraphQL v15
  • GitHub Check: Unit Test on Node 22 (ubuntu-latest) and GraphQL v16
  • GitHub Check: Unit Test on Node 22 (ubuntu-latest) and GraphQL v15
  • GitHub Check: Unit Test on Node 20 (ubuntu-latest) and GraphQL v16
  • GitHub Check: Unit Test on Node 20 (ubuntu-latest) and GraphQL v15
  • GitHub Check: Unit Test on Node 18 (ubuntu-latest) and GraphQL v16
  • GitHub Check: Unit Test on Node 18 (ubuntu-latest) and GraphQL v15
  • GitHub Check: Unit Test on Bun (ubuntu-latest) and GraphQL v16
  • GitHub Check: Full Check on GraphQL v16
  • GitHub Check: Unit Test on Bun (ubuntu-latest) and GraphQL v15
  • GitHub Check: deployment
🔇 Additional comments (6)
.changeset/chilly-icons-guess.md (1)

1-11: Well-documented changeset for the bug fix

The changeset clearly describes the bug fix in the mergeDeep function and provides specific examples of inputs and their expected outputs. This documentation helps users understand the new behavior and is aligned with the implementation changes.

packages/utils/src/mergeDeep.ts (2)

15-20: LGTM: Early return for edge cases improves function clarity

These additions handle the edge cases as described in the changeset:

  1. Returning undefined when an empty array is passed
  2. Returning the single source when only one item is provided

This is a good optimization that avoids unnecessary processing when the result is deterministic.


63-65: LGTM: Properly skipping null/undefined values

This change correctly implements the behavior described in the changeset, where nullish values in the sources array are ignored during the merge process. This prevents errors that could occur when trying to process null or undefined as objects.

packages/utils/tests/mergeDeep.test.ts (3)

76-78: Good test for filtering nullish values

This test case properly verifies that the function ignores undefined values in the sources array, aligning with the fix implemented in the main function.


80-82: Good test for single empty object

This test confirms that the function correctly handles a source array containing only an empty object, returning that empty object as expected.


84-86: Good test for empty sources array

This test verifies the new behavior where an empty sources array returns undefined, which is consistent with the function implementation.

Copy link
Contributor

github-actions bot commented Mar 7, 2025

💻 Website Preview

The latest changes are available as preview in: https://pr-7012.graphql-tools.pages.dev

@ardatan ardatan merged commit fd105f4 into master Sep 24, 2025
5 checks passed
@ardatan ardatan deleted the fix-merge-deepo branch September 24, 2025 15:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mergeDeep behaviour with undefined values changed in 10.6.2

2 participants