Skip to content

[core] fix: skip files without a document and narrow validate/hash types under strict mode (#4683) - #10991

Merged
eddeee888 merged 3 commits into
masterfrom
claude/happy-rubin-edqpid
Sep 26, 2026
Merged

eddeee888 merged 3 commits into
masterfrom
claude/happy-rubin-edqpid

Conversation

@eddeee888

@eddeee888 eddeee888 commented Sep 25, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Part of the strict: true tracker #10985. This fixes the 4 errors in graphql-codegen-core that appear when strict is on.

  • codegen.ts (TS2345, twice): transformedDocuments.flatMap(d => d.document) has type (DocumentNode | undefined)[]. It now filters out files without a document using an inline guard (d.document ? [d.document] : []), so validateGraphQlDocuments no longer gets undefined. 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 concatenated doc.hash, which is string | null | undefined, even though an earlier .some(...) check had already returned early for non-string hashes. The hashes are now collected once into documentHashes and checked with documentHashes.every(hash => typeof hash === 'string'). TypeScript 5.5+ infers that callback as a type guard, so documentHashes is known to be string[] where the key is built. The result is the same as the old .some(...) check.
  • execute-plugin.ts (TS2722): TypeScript lost the plugin.validate narrowing inside the profiler.run callback. It is now saved to a local const validate = plugin.validate before the check, and the callback calls validate(...). The function is no longer called as a method on plugin, so a validate that relied on this would 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, and validate is no longer called with the plugin as this. The CLI always passes files that have a document, and no in-repo plugin uses this in validate, so generated output is unchanged. There is a patch changeset for @graphql-codegen/core.

Related #4683

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • tsc --noEmit -p tsconfig.json with the tracker's strict: true config applied locally: 0 errors in graphql-codegen-core (4 before). With the repo's normal config it still passes with 0 errors.
  • Unit tests (graphql-codegen-core)
  • Unit tests (graphql-codegen-cli): 72 fail in this environment, but the same 72 fail on unmodified master, 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

…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-bot

changeset-bot Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 5109cc4

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

This PR includes changesets to release 1 package
Name Type
@graphql-codegen/core 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

@github-actions

github-actions Bot commented Sep 25, 2026 •

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
@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 ↗︎

Comment thread packages/graphql-codegen-core/src/codegen.ts Outdated
Comment thread packages/graphql-codegen-core/src/execute-plugin.ts
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