Skip to content

fix: graphql@17.0.0 compatibility - #1256

Open
Tony133 wants to merge 1 commit into
mercurius-js:masterfrom
Tony133:fix/upgrade-graphql-v17
Open

fix: graphql@17.0.0 compatibility#1256
Tony133 wants to merge 1 commit into
mercurius-js:masterfrom
Tony133:fix/upgrade-graphql-v17

Conversation

@Tony133

@Tony133 Tony133 commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Proposal:

Changes:

  • index.js: buildExecutionContext was removed from graphql/execution/execute in graphql 17 → feature-detected against its drop-in successor validateExecutionArgs (same signature/behavior), falling back to buildExecutionContext on graphql@16.
  • lib/errors.js: GraphQLError's positional constructor was fully removed in graphql 17 (it's supported since graphql@16.3, so this works on both). toGraphQLError() used the old positional args, which silently dropped originalError — breaking status code mapping (validation/CSRF/persisted-query errors returned 200 instead of 400/405). Switched to the new options-object signature.
  • index.js: graphql 17 tags AST loc.source with a non-cloneable Symbol, so structuredClone() crashed on pre-parsed documents (e.g. graphql-tag). Replaced with rfdc (already in the fastify dep tree) for cloning — faster than structuredClone/JSON, and it naturally skips the Symbol-keyed brand without needing to strip loc.
  • package.json: widened peerDependencies.graphql to ^16.8.0 || ^17.0.0; added rfdc as an explicit dependency.
  • test/directives.test.js: the scalar-coercion error message wording differs between graphql-js 16 and 17, so the expected string is now resolved at runtime based on the installed graphql version (via the version export — require('graphql/package.json') no longer works on @17, its exports map blocks arbitrary subpaths).
  • test/app-decorator.test.js: fixed a wrong assertion — mercurius wraps validation GraphQLErrors in MER_ERR_GQL_VALIDATION.errors[], the test was checking the wrong object (e instead of e.errors[0]).
  • .github/workflows/ci.yml: added a graphql-version: [16, 17] matrix dimension, with a step that installs the matrix's graphql version after the regular install (--no-save), so both majors are covered in CI. Add node 26 to test matrix.

Note:

@Tony133
Tony133 marked this pull request as ready for review July 23, 2026 08:26

@mcollina mcollina left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I would prefer if we could support both 16 and 17 at the same time, as a lot of people would not be able to upgrade graphql in time. This would require to fiddle with CI so that we run tests for both versions.

Comment thread index.js
@Tony133

Tony133 commented Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

I would prefer if we could support both 16 and 17 at the same time, as a lot of people would not be able to upgrade graphql in time. This would require to fiddle with CI so that we run tests for both versions.

yes I agree, I just wanted to know what you thought first 😉

@mcollina mcollina mentioned this pull request Jul 23, 2026
1 task
@Tony133
Tony133 force-pushed the fix/upgrade-graphql-v17 branch from 23bc028 to 4587340 Compare July 23, 2026 10:26
@Tony133

Tony133 commented Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

I updated the files so as to have compatibility for graphql 16 and 17 and I also updated the CI file so it separates the tests for graphql 16 and 17, plus I added nodejs v26 🔥

@Tony133
Tony133 requested a review from mcollina July 23, 2026 10:36

@mcollina mcollina left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

index.js has a lot of pure formatting changes (prettier?). Please revert them

@mcollina

Copy link
Copy Markdown
Collaborator

keeping as semver-major as safety measure.

@Tony133

Tony133 commented Jul 29, 2026

Copy link
Copy Markdown
Contributor Author

index.js has a lot of pure formatting changes (prettier?). Please revert them

I think it's my editor that formats everything to a maximum of 80 columns 😄

@mcollina

Copy link
Copy Markdown
Collaborator

Please revert, this is very hard to review

@Tony133
Tony133 force-pushed the fix/upgrade-graphql-v17 branch 4 times, most recently from 8e145bc to 7a38023 Compare July 29, 2026 15:31
@Tony133

Tony133 commented Jul 29, 2026

Copy link
Copy Markdown
Contributor Author

Please revert, this is very hard to review

Ok, I think I've fixed it, see commit here: 7a38023. Sorry about the issues with the code indentation 🙏🏻

@mcollina mcollina left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

lgtm

@mcollina

Copy link
Copy Markdown
Collaborator

there are conflicts

@Tony133
Tony133 force-pushed the fix/upgrade-graphql-v17 branch from 7a38023 to 344bfd8 Compare July 30, 2026 06:17
@Tony133

Tony133 commented Jul 30, 2026

Copy link
Copy Markdown
Contributor Author

there are conflicts

I don't see any conflicts to resolve 😄, the CI is all green 🙌 ✅

@Tony133 Tony133 closed this Jul 30, 2026
@Tony133 Tony133 reopened this Jul 30, 2026
@Tony133

Tony133 commented Jul 30, 2026

Copy link
Copy Markdown
Contributor Author

I accidentally closed the PR 😅, sorry

@Tony133

Tony133 commented Jul 30, 2026

Copy link
Copy Markdown
Contributor Author

ok, the CI is all green 🙌 ✅

lv10 added a commit to nearform/the-graphql-workshop that referenced this pull request Aug 14, 2026
mercurius@16.10.0 (latest) peers graphql@^16.0.0, and both
@mercuriusjs/federation and @mercuriusjs/gateway depend on
mercurius@^16.0.0, so graphql 17 cannot be installed. The upstream
compatibility fix (mercurius-js/mercurius#1256) is still unmerged;
without it 73/376 mercurius tests fail under graphql 17.

Dependabot PR #986 was closed as unmergeable. This ignore rule stops it
being re-raised weekly while leaving graphql 16.x minor/patch updates
flowing.

Co-authored-by: Luis Villamarin <luis.villamarin@nearform.com>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants