Skip to content

fix(mercurius): require the gateway release that resolves union fields - #4190

Merged
kamilmysliwiec merged 1 commit into
masterfrom
fix/mercurius-gateway-union-floor
Oct 26, 2026
Merged

kamilmysliwiec merged 1 commit into
masterfrom
fix/mercurius-gateway-union-floor

Conversation

@kamilmysliwiec

Copy link
Copy Markdown
Member

PR Checklist

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)

PR Type

  • Bugfix

What is the current behavior?

#2165: with the Mercurius gateway, a union of entity references used as an object field type (e.g. User.favoriteItem: FavoriteItemUnion whose members live in another subgraph) fails with Cannot return null for non-nullable field Song.title., while the same union as a Query return type works. The cause was the gateway's query planner, which never sent the _entities fetch for such members. It was fixed upstream in mercurius-js/mercurius-gateway#122, released in @mercuriusjs/gateway 5.1.0. The peer range here still allows ^5.0.0.

Issue Number: #2165

What is the new behavior?

  • @mercuriusjs/gateway peer range: ^5.1.0 (it stays optional; the devDependency is already 5.2.0).
  • New e2e spec tests/e2e/federated-union-field.spec.ts: a code-first users subgraph with Song/Movie entity stubs in a createUnionType union, used as an object field (directly and via @ResolveField) and as a Query return type, composed by the Mercurius gateway with a media subgraph that resolves the references. It passes with 5.1.0+ and fails with 5.0.0 with the error from the issue.

Closes #2165

Does this PR introduce a breaking change?

  • Yes
  • No

Raising the peer floor is formally semver-major, but 5.0.x can't resolve these fields.

@mercuriusjs/gateway before 5.1.0 never fetched the _entities of union
members that live in another subgraph when the union is an object field
type, so such fields failed with "Cannot return null for non-nullable
field". 5.1.0 fixed it (mercurius-js/mercurius-gateway#122). Raise the
peer floor to ^5.1.0 and add a regression test for field- and
query-level unions of entity references.

Closes #2165
@kamilmysliwiec
kamilmysliwiec merged commit 12ac497 into master Oct 26, 2026
1 check 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.

Type references in union doesn't get resolved when used as return type for an Object field

1 participant