Skip to content

Conversation

cdaringe
Copy link
Contributor

@cdaringe cdaringe commented Feb 23, 2025

🚨 IMPORTANT: Please do not create a Pull Request without creating an issue first.

Any change needs to be discussed before proceeding. Failure to do so may result in the rejection of
the pull request.

Description

Link directives are not correctly merged correctly when the URL matches.

Closes #6929 (comment)

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as
    expected)
  • This change requires a documentation update

Screenshots/Sandbox (if appropriate/relevant):

Adding links to sandbox or providing screenshots can help us understand more about this PR and take
action on it as appropriate

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can
reproduce. Please also list any relevant details for your test configuration

  • unit testes

Test Environment:

  • OS: macOS
  • @graphql-tools/...:
  • NodeJS: 20.x

Checklist:

  • I have followed the
    CONTRIBUTING doc and the
    style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • 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
  • [na] Any dependent changes have been merged and published in downstream modules

Further comments

If this is a relatively large or complex change, kick off the discussion by explaining why you chose
the solution you did and what alternatives you considered, etc...

Copy link

changeset-bot bot commented Feb 23, 2025

⚠️ No Changeset found

Latest commit: 9f5d65b

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

Copy link
Contributor

coderabbitai bot commented Feb 23, 2025

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Summary by CodeRabbit

  • New Features
    • Schema merging now treats similarly named link directives with different URLs as distinct, preventing accidental consolidation and preserving both directives.
  • Tests
    • Added tests that verify the improved merging behavior for link directives across merged schemas to ensure accurate and predictable results.

Walkthrough

Added link-directive helpers and updated directive-merge logic so @link directives are compared by their url argument; when two @link directives have different URLs they are not merged. Tests were added to cover merging behavior for schemas with differing @link directives.

Changes

Cohort / File(s) Change Summary
Directive merge logic
packages/merge/src/typedefs-mergers/directives.ts
- Added helpers: isLinkDirective(directive), getLinkDirectiveURL(directive).
- Adjusted matching/ distinctness checks to treat @link directives as distinct when URLs differ.
- Updated mergeDirectives to preserve separate @link directives when URLs are different.
Tests for @link behavior
packages/merge/tests/merge-typedefs.spec.ts
- Added a test verifying merge outcome when schemas contain @link directives with identical vs. different url args.
- Minor formatting tweak between tests.

Sequence Diagram(s)

sequenceDiagram
    participant Merger as mergeDirectives
    participant Match as isMatchingDirective
    participant Distinct as isDirectiveDistinctByArguments
    participant LinkUtil as isLinkDirective / getLinkDirectiveURL

    Merger->>Match: compare incoming directive with existing
    Match->>Distinct: determine distinctness for @link
    Distinct->>LinkUtil: check if both are @link and fetch URLs
    LinkUtil-->>Distinct: return URLs (or undefined)
    Distinct-->>Match: return distinctness result
    Match-->>Merger: indicate merge or push-as-new
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

I'm a rabbit in the code-lined glen,
Hopping through directives, now and then.
Two @link paths meet but don't collide,
Each URL kept safe, side by side.
Carrots, tests, and tidy merge—what a ride!

✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dcefcd5 and 9f5d65b.

📒 Files selected for processing (2)
  • packages/merge/src/typedefs-mergers/directives.ts (2 hunks)
  • packages/merge/tests/merge-typedefs.spec.ts (1 hunks)

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.

import { isSome } from '@graphql-tools/utils';
import { Config } from './merge-typedefs.js';

const isLinkDirective = (directive: DirectiveNode): boolean => directive.name.value === 'link';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

not sure if we already have AST narrowing fns. Further, I didn't see a LinkDirective type, which woulda been nice. Not going to add anything like that without discussion :)

@cdaringe cdaringe marked this pull request as ready for review February 23, 2025 18:24
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 (2)
packages/merge/src/typedefs-mergers/directives.ts (2)

13-18: Consider handling non-string URL arguments
Currently, the function only checks for a StringValue. If there's a scenario where url could be of a different type, the function might silently ignore it.


20-29: Potential extension to handle arguments for other directives
Right now, non-@link directives are never considered distinct by their arguments. If future requirements demand argument-based distinctness checks across all directives, consider generalizing this logic.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between aaf0fc4 and dcefcd5.

📒 Files selected for processing (2)
  • packages/merge/src/typedefs-mergers/directives.ts (2 hunks)
  • packages/merge/tests/merge-typedefs.spec.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • 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
🔇 Additional comments (5)
packages/merge/src/typedefs-mergers/directives.ts (4)

11-12: Straightforward name check for @link directive
Implementation is concise and does what it says—no issues identified.


30-30: Simple, readable matching predicate
This helper improves clarity by centralizing the directive name comparison.


36-39: Consistent logic for directive existence check
By deferring arguments-based distinctness to isDirectiveDistinctByArguments, this function cleanly separates concerns.


125-125: Confirm handling of multiple matching directives
findIndex returns the first matching directive. If the schema contains multiple directives with the same name, confirm that this logic is appropriate.

packages/merge/tests/merge-typedefs.spec.ts (1)

1707-1738: Excellent validation of @link directive merging
This test thoroughly ensures that identical directives are merged while distinct ones (i.e., those with different URLs) are preserved.

theguild-bot and others added 2 commits September 24, 2025 18:00
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
@ardatan ardatan merged commit 1a6251d into ardatan:master Sep 24, 2025
4 checks passed
@ardatan
Copy link
Owner

ardatan commented Sep 24, 2025

Thanks for the PR! Sorry for the late review!

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 produces incorrect output schema
3 participants