Skip to content

Reject deprecated field if interface field is not - #349

Merged
n1ru4l merged 1 commit into
mainfrom
deprecated-interface-fix
Nov 23, 2026
Merged

n1ru4l merged 1 commit into
mainfrom
deprecated-interface-fix

Conversation

@jdolle

@jdolle jdolle commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

Background

Composition can succeed and return a supergraph and public schema that are not valid GraphQL: a field is @deprecated while the interface field it implements is not. The spec forbids this in IsValidImplementation ("If field is deprecated then implementedField must also be deprecated"). graphql-js 17 enforces the rule in validateSchema and graphql-js 16 does not, so the output fails validation for anyone on graphql 17.

It can happen inside one subgraph, and also across subgraphs that are each valid on their own:

# catalog
interface Product {
  sku: String!
}

type Book implements Product @key(fields: "sku") {
  sku: String!
}
# inventory
type Book @key(fields: "sku") {
  sku: String! @deprecated(reason: "Use upc")
  upc: String!
}

Description

Adds a supergraph validation rule, DeprecatedInterfaceFieldImplementationRule, covering object and interface fields. Composition now fails with INVALID_GRAPHQL, using the same message as graphql-js 17:

Interface field Product.sku is not deprecated, so implementation field Book.sku must not be deprecated.

Opt-out. The rule can be turned off with disableValidationRules: ["DeprecatedInterfaceFieldImplementationRule"].

Checklist

  • Input validation
  • Error handling and logging
  • Testing

@jdolle
jdolle requested a review from kamilkisiela November 21, 2026 00:23
@jdolle jdolle self-assigned this Nov 21, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Snapshot Release (alpha)

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

Package Version Info
@theguild/federation-composition 0.27.3-alpha-20261121002318-c10d9c533094485268fba398a6759c2407948285 npm ↗︎ unpkg ↗︎

@jdolle
jdolle requested a review from n1ru4l November 21, 2026 00:32

@n1ru4l n1ru4l left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Seems cheaper to do things like this instead of running another graphql validation pass on the output...

@n1ru4l
n1ru4l merged commit 78c6af6 into main Nov 23, 2026
5 checks passed
@n1ru4l
n1ru4l deleted the deprecated-interface-fix branch November 23, 2026 08:12
kamilkisiela added a commit to graphql-hive/federation-composition-rs that referenced this pull request Dec 3, 2026
Ports upstream
[v0.27.3](https://github.com/graphql-hive/federation-composition/releases/tag/v0.27.3)
and
[v0.28.0](https://github.com/graphql-hive/federation-composition/releases/tag/v0.28.0),
one commit each, and moves `UPSTREAM` to `v0.28.0`.

## v0.27.3

- `DeprecatedInterfaceFieldImplementationRule`
(graphql-hive/federation-composition#349): a deprecated field whose
interface field is not deprecated fails composition with
`INVALID_GRAPHQL`, since graphql-js 17 rejects such a schema.
- The new `INVALID-GRAPHQL` test and the updated `huge-schema` fixture
are ported.

## v0.28.0

From graphql-hive/federation-composition#347:

- `composeSchemaContract` gains a `skipSatisfiability` option
(`ComposeSchemaContractOptions`; `compose_schema_contract` takes an
`options` argument).
- `composeServicesWithContracts` (new
`contracts/supergraph_state_contract.rs`) composes the supergraph once
and derives each contract from its state: the tag filter is applied to
the state, only the six `@inaccessible` rules run
(`validate_inaccessible_usage`), the supergraph is built again, and the
state is restored for the next contract. When the subgraphs fail to
compose, each contract is composed in full.
- The three filter predicates (`isExcludedByFilter`,
`isExcludedByExcludeFilter`, `isArgumentExcludedByFilter`) are shared by
both filters in `tag_extraction.rs`.
- The wasm bindings and the npm shim export
`composeServicesWithContracts` and `SchemaContract`. The shim shares a
contract's unchanged definitions with the supergraph's document, as
upstream does.

Where the Rust differs in mechanism, not in result:

- **External fields' `@tag`s.** Upstream reads them from the subgraph
states' types, which the Rust drops after merging each subgraph. A
stripped subgraph state now keeps its tagged fields' tags
(`SubgraphState::field_tags`); untagged fields cost nothing.
- **Restoring the state.** Upstream mutates the state through undo
closures. The Rust decides every change from the state read-only,
applies them, and logs each previous value by its position, so `restore`
puts it back.
- **"a contract reuses the definitions it does not change"** checks JS
object identity. It passes on wasm through the shim; the Rust test
compares the printed definitions, since a Rust success is its SDL.

## Verification

- `pnpm conformance` at v0.28.0: 7,401 passed, 25 skipped, 8 todo on
wasm (same as upstream's own TypeScript); 3,714/3,714 compositions
identical.
- `cargo test --workspace`: the suite has 3,823 passed, 17 ignored;
graphql-js differentials, doctests and unit tests pass. The random-tag
tests on `dgs` and `stars-stuff` compare every derived contract with the
full per-contract composition.
- `pnpm test:npm`: 16/16.
- clippy (native and wasm32) and `cargo doc`, with `-D warnings`.
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.

2 participants