Skip to content

fix(merge): preserve repeatable directives on schema definitions - #8349

Merged
ardatan merged 1 commit into
ardatan:masterfrom
aarne:fix/merge-schema-def-repeatable-directives
Aug 7, 2026
Merged

fix(merge): preserve repeatable directives on schema definitions#8349
ardatan merged 1 commit into
ardatan:masterfrom
aarne:fix/merge-schema-def-repeatable-directives

Conversation

@aarne

@aarne aarne commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Description

mergeGraphQLNodes collects all directive definitions into a registry and passes it to every named-type merger, but not to mergeSchemaDefs — even though that function has accepted a directives parameter since #7249 (it was added to the signature but the call site was never updated). Without the registry, mergeDirectives cannot tell that a schema-level directive is declared repeatable, so repeated instances on schema definitions and extend schema extensions are collapsed into a single directive with merged arguments.

This PR passes the registry through at the call site (one line), enables the it.todo('supports multiple schema extensions') left behind by #7249, and adds a regression test for a repeatable directive on schema definitions across documents (which fails without the fix).

Federation @link mostly escaped this bug via repeatableLinkImports and the same-name/different-url carve-out in mergeDirectives; SDL-declared repeatable on SCHEMA directives had no such fallback.

Fixes #8348

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • New regression test keeps repeatable directives on schema definitions across documents — fails without the one-line fix, passes with it
  • Enabled the previously commented-out supports multiple schema extensions todo test
  • Full packages/merge and packages/schema suites pass (194 tests)

Test Environment:

  • OS: Linux
  • @graphql-tools/merge: master (9.2.2)
  • NodeJS: 26

Checklist:

  • I have followed the CONTRIBUTING doc and the style guidelines of this project
  • I have performed a self-review of my own code
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests and linter rules pass locally with my changes

🤖 Generated with Claude Code

mergeGraphQLNodes collects directive definitions and passes them to every
named-type merger, but not to mergeSchemaDefs — even though it already
accepts a directives parameter (added in ardatan#7249, never wired up). Without
the registry, mergeDirectives cannot tell that a schema-level directive is
repeatable, so repeated instances on schema definitions and extensions are
collapsed into one with merged arguments.

Pass the registry through, enable the it.todo left in ardatan#7249, and add a
regression test for repeatable directives on schema definitions across
documents.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Aug 6, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7dabb1a

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

This PR includes changesets to release 6 packages
Name Type
@graphql-tools/merge Patch
@graphql-tools/schema Patch
graphql-tools Patch
@graphql-tools/load Patch
@graphql-tools/mock Patch
@graphql-tools/node-require 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

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes

    • Fixed schema merging so repeatable directives on schema definitions and extensions are preserved separately with their distinct arguments.
    • Ensured repeatable @link and @tag directives remain available and retain their document order.
  • Tests

    • Added coverage for repeatable directives across multiple schema definitions and extensions.

Walkthrough

The schema merge path now passes collected directive definitions to mergeSchemaDefs. Tests verify that repeatable @link and @tag directives remain separate and preserve their order.

Changes

Schema directive merging

Layer / File(s) Summary
Preserve repeatable schema directives
packages/merge/src/typedefs-mergers/merge-nodes.ts, packages/merge/tests/merge-typedefs.spec.ts, .changeset/merge-schema-def-repeatable-directives.md
mergeGraphQLNodes passes the collected directives map to mergeSchemaDefs. Tests cover repeatable schema-level @link directives on extensions and repeatable @tag directives across definitions. A patch changeset documents the fix.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested reviewers: ardatan

Poem

I’m a rabbit guarding tags in a row,
Keeping each directive where it should go.
@link stays distinct, @tag keeps its place,
The schema merge now runs with grace.
Hop, hop—repeatable facts remain!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the primary fix for preserving repeatable directives on schema definitions.
Description check ✅ Passed The description directly explains the schema merging bug, the implementation fix, regression tests, and test results.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@ardatan

ardatan commented Aug 7, 2026

Copy link
Copy Markdown
Owner

Thanks @aarne !

@ardatan
ardatan merged commit 7fe0319 into ardatan:master Aug 7, 2026
12 of 44 checks passed
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.

mergeTypeDefs collapses repeatable directives on schema definitions / extensions

2 participants