Conversation
…operation types On graphql@17, SchemaExtensionNode.operationTypes is undefined (not []) for a schema extension that declares no operation types itself, e.g. `extend schema @link(...)`. The useSchemaDefinition backfill in mergeGraphQLTypes read that field through a `|| []` fallback, which created a new array disconnected from schemaDef.operationTypes. The backfilled query/mutation/subscription entries were pushed into that throwaway array and then discarded, since the final check still read the original (still undefined) field. The merged output kept an empty extend schema block, forcing consumers to declare `schema { query: Query }` manually. Fix by normalizing schemaDef.operationTypes to [] in place before reading it, so the backfill mutates the array actually attached to schemaDef. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Add coverage alongside the existing query-only backfill test: - all three (query/mutation/subscription) backfilled when all three root types exist - only the operation types whose root type actually exists get backfilled (partial case) Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Use `??=` to normalize schemaDef.operationTypes in one expression, and rely on the fact that `operationTypes` is now the same array reference as `schemaDef.operationTypes` — the final gate can just check operationTypes.length instead of re-reading schemaDef.operationTypes. No behavior change; same tests pass. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
graphql-js's SchemaDefinitionNode/SchemaExtensionNode.operationTypes is
readonly. The previous 'schemaDef.operationTypes ??= []' mutated it
directly, which is a TS2540 type error (caught by tsc/editors, but not
by this repo's babel-jest transform, which doesn't type-check - hence
it slipped through CI-equivalent test runs undetected).
Copy schemaDef.operationTypes into a fresh mutable array instead of
writing back into the AST node, and build a new node
({ ...schemaDef, operationTypes }) when storing the backfilled result,
rather than mutating schemaDef in place.
Verified with a full 'tsc --noEmit' across the repo (0 errors) as well
as the merge/schema test suites (197 passing).
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 3a3e05f The changes in this PR will be included in the next version bump. This PR includes changesets to release 6 packages
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 |
Contributor
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: trueThanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Collaborator
Author
|
Oops already done here |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
extend schemasyntax overrides the default implicitschema { query: Query, mutation: Mutation, subscription: Subscription }and creates an emptyschema { }instead.On graphql < 17, this is backfilled correctly i.e. if there is
type Query, themergefunction will createschema { query: Query }.On graphql@17,
SchemaExtensionNode.operationTypesisundefinedinstead of an empty array. The backfill logic built the missingquery/mutation/subscriptionentries into a fresh, disconnected array instead of the one attached to the schema node, so they were computed and then discarded — leaving the merged output with an emptyextend schema { ... }and forcing consumers to declareschema { query: Query }manually.This PR fixes it by creating a default empty array when
operationTypesis undeclared.Related graphql-hive/console#8394 (comment)
Type of change
How Has This Been Tested?