Repository navigation
[core] fix: skip files without a document and narrow validate/hash types under strict mode (#4683) - #10991
Merged
Conversation
…pes under strict mode (#4683) Under `strict: true`, core had 4 type errors: - `transformedDocuments.flatMap(d => d.document)` is `(DocumentNode | undefined)[]` (TS2345, x2). Filter out files without a `document` with an inline guard instead of passing `undefined` to `validateGraphQlDocuments`. - The cache key concatenated `doc.hash` (`string | null | undefined`) even though `.some(...)` had already ruled non-strings out (TS2769). Collect the hashes once and use an `every` type guard so the narrowing carries through. - `plugin.validate` narrowing was lost inside the `profiler.run` callback (TS2722). Capture it in a local, bound to the plugin. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AKWv2u4brsoCsbLcCkiwcZ eddeee888:oss:issue-fix
🦋 Changeset detectedLatest commit: 5109cc4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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
🚀 Snapshot Release (
|
| Package | Version | Info |
|---|---|---|
@graphql-codegen/core |
6.2.1-alpha-20260926075408-5109cc46d1b5058cdc796ba8baf625025d380af2 |
npm ↗︎ unpkg ↗︎ |
@graphql-codegen/add |
7.1.1-alpha-20260926075408-5109cc46d1b5058cdc796ba8baf625025d380af2 |
npm ↗︎ unpkg ↗︎ |
@graphql-codegen/typescript-document-nodes |
6.1.1-alpha-20260926075408-5109cc46d1b5058cdc796ba8baf625025d380af2 |
npm ↗︎ unpkg ↗︎ |
eddeee888
commented
Sep 26, 2026
eddeee888
commented
Sep 26, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AKWv2u4brsoCsbLcCkiwcZ
…4683) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AKWv2u4brsoCsbLcCkiwcZ
eddeee888
marked this pull request as ready for review
September 26, 2026 08:12
This was referenced Sep 25, 2026
24 of 25 tasks
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
Part of the
strict: truetracker #10985. This fixes the 4 errors ingraphql-codegen-corethat appear whenstrictis on.codegen.ts(TS2345, twice):transformedDocuments.flatMap(d => d.document)has type(DocumentNode | undefined)[]. It now filters out files without adocumentusing an inline guard (d.document ? [d.document] : []), sovalidateGraphQlDocumentsno longer getsundefined. This skips files without a document the same way document-nodes does ([document-nodes] fix: skip files without a document and annotate filter param under strict mode (#4683) #10990).codegen.ts(TS2769): the validation cache key concatenateddoc.hash, which isstring | null | undefined, even though an earlier.some(...)check had already returned early for non-string hashes. The hashes are now collected once intodocumentHashesand checked withdocumentHashes.every(hash => typeof hash === 'string'). TypeScript 5.5+ infers that callback as a type guard, sodocumentHashesis known to bestring[]where the key is built. The result is the same as the old.some(...)check.execute-plugin.ts(TS2722): TypeScript lost theplugin.validatenarrowing inside theprofiler.runcallback. It is now saved to a localconst validate = plugin.validatebefore the check, and the callback callsvalidate(...). The function is no longer called as a method onplugin, so avalidatethat relied onthiswould lose it. None of the plugins in this repo do.I used type guards instead of
!assertions. There are two runtime changes: files without a document are skipped during validation, andvalidateis no longer called with the plugin asthis. The CLI always passes files that have a document, and no in-repo plugin usesthisinvalidate, so generated output is unchanged. There is a patch changeset for@graphql-codegen/core.Related #4683
Type of change
How Has This Been Tested?
tsc --noEmit -p tsconfig.jsonwith the tracker'sstrict: trueconfig applied locally: 0 errors ingraphql-codegen-core(4 before). With the repo's normal config it still passes with 0 errors.graphql-codegen-core)graphql-codegen-cli): 72 fail in this environment, but the same 72 fail on unmodifiedmaster, so this change doesn't cause them. CI is the source of truth for these.🤖 Generated with Claude Code
https://claude.ai/code/session_01AKWv2u4brsoCsbLcCkiwcZ