Skip to content

fix(internals-js): recognize @oneOf as a built-in directive - #3467

Open
DevRichter wants to merge 2 commits into
apollographql:mainfrom
DevRichter:fix/oneof-builtin-directive
Open

fix(internals-js): recognize @oneOf as a built-in directive#3467
DevRichter wants to merge 2 commits into
apollographql:mainfrom
DevRichter:fix/oneof-builtin-directive

Conversation

@DevRichter

@DevRichter DevRichter commented Aug 5, 2026

Copy link
Copy Markdown

What

Adds oneOf to graphQLBuiltInDirectivesSpecifications in internals-js/src/definitions.ts so it's recognized as a built-in directive, the same way deprecated/specifiedBy/defer/stream already are. Also bumps the repo's dev-only graphql pin from 16.8.1 to 16.9.0.

Why

Fixes #3437. @oneOf has been part of the GraphQL spec since graphql-js 16.9, but internals-js's built-in directive whitelist was never updated for it. As a result, any subgraph SDL using @oneOf on an input type fails with "Unknown directive" — both when building/printing a single subgraph schema and when composing multiple subgraphs, since @apollo/subgraph and @apollo/composition share this validation.

The graphql version bump is required for the fix to actually take effect (and to be testable in this repo): Schema#toGraphQLJSSchema builds the final schema via graphql-js's own buildASTSchema, and @oneOf/isOneOf aren't implemented in graphql-js until 16.9.0 — 16.8.1 (the repo's current pin) rejects @oneOf outright, independent of this fix. 16.9.0 is the minimum needed, chosen over jumping to latest to keep the change scoped.

How

  • INPUT_OBJECT location, no arguments — matches the directive's definition in the GraphQL spec and in graphql-js's own specifiedDirectives.
  • Verified the fix correctly sets GraphQLInputObjectType.isOneOf = true on the resulting graphql-js schema, so this isn't just a printing fix — runtime "exactly one field" enforcement works too.
  • Added a unit test in definitions.test.ts covering the input-object case (mirroring the existing @specifiedBy scalar test in the same describe block) and an integration test in subgraphValidation.test.ts covering the buildSubgraph/printSchema round trip that @apollo/subgraph and @apollo/composition rely on.

@DevRichter
DevRichter requested a review from a team as a code owner August 5, 2026 15:13
@apollo-cla

Copy link
Copy Markdown

@DevRichter: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Apollo Contributor License Agreement here: https://contribute.apollographql.com/

@changeset-bot

changeset-bot Bot commented Aug 5, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 36cee05

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

This PR includes changesets to release 7 packages
Name Type
@apollo/federation-internals Patch
@apollo/gateway Patch
@apollo/composition Patch
@apollo/query-planner Patch
@apollo/query-graphs Patch
@apollo/subgraph Patch
apollo-federation-integration-testsuite 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

@apollo-librarian

apollo-librarian Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

✅ AI Style Review — No Changes Detected

No MDX files were changed in this pull request.

Review Log: View detailed log

This review is AI-generated. Please use common sense when accepting these suggestions, as they may not always be accurate or appropriate for your specific context.

@OneOf has been part of the GraphQL spec since graphql-js 16.9, but
internals-js's built-in directive whitelist was never updated for it,
so any subgraph SDL using @OneOf on an input type failed with
"Unknown directive" in both buildSubgraphSchema and composeServices.

Also bumps the repo's dev-only graphql pin from 16.8.1 to 16.9.0, the
minimum version where @oneOf/isOneOf are implemented in graphql-js,
since Schema#toGraphQLJSSchema builds the final schema via graphql-js's
own buildASTSchema and needs that support for this fix to take effect.

Fixes apollographql#3437
@DevRichter
DevRichter force-pushed the fix/oneof-builtin-directive branch from fe81dc7 to 635d6c1 Compare August 5, 2026 15:17
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.

Unknown directive "@oneOf".

2 participants