Skip to content

[graphql-modules-preset] fix: skip sources without a location or document under strict mode (#4683) - #10993

Merged
eddeee888 merged 3 commits into
masterfrom
claude/adoring-gauss-71v94u
Sep 27, 2026
Merged

eddeee888 merged 3 commits into
masterfrom
claude/adoring-gauss-71v94u

Conversation

@eddeee888

@eddeee888 eddeee888 commented Sep 26, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Part of the strict-mode rollout tracked in #10985. This PR fixes the 7 errors presets/graphql-modules hits when the root tsconfig turns on strict: true. It also fixes getConfigValue in visitor-plugin-common, which was the root cause of one of those errors.

visitor-plugin-common

  • getConfigValue's value parameter is now typed T | null | undefined. T used to be inferred from the nullable config value, so the result was X | undefined even with a non-nullable default. T now comes from the default, so the result is non-nullable. Under strict mode this also fixes the two TS2345 errors in base-documents-visitor.ts (operationDeclarationKind, avoidOptionals). With strictNullChecks off, as on master today, the signature is unchanged. No caller passes an explicit type argument.

presets/graphql-modules

  • builder.ts: node.interfaces?.length > 0 compares a value that may be undefined. It now defaults to 0 (TS18048).
  • index.ts: Source.document is optional. Sources without one are now skipped before concatAST, the same way core does it (TS2345).
  • index.ts: useGraphQLModules typechecks through the fixed getConfigValue (TS2322).
  • index.ts: .filter(Boolean) doesn't narrow the type of rootTypes. It now uses a typeof name === 'string' type guard (TS2322).
  • utils.ts: Source.location is optional, and path.normalize(undefined) throws. groupSourcesByModule now skips sources without one (TS2345).

These are local guards rather than ! assertions, following the review feedback on #10990. CLI output is unchanged. Patch changesets are included for both packages.

Related #4683

Type of change

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

How Has This Been Tested?

  • Type check with chore: enable strict: true in root tsconfig (#4683) #10985's strict tsconfig.json: 0 errors in presets/graphql-modules (7 before), and 2 fewer in visitor-plugin-common
  • Type check on the current tsconfig.json: 0 errors
  • Unit tests for presets/graphql-modules, visitor-plugin-common and the typescript plugins, after a build: all passing

🤖 Generated with Claude Code

https://claude.ai/code/session_01XSMiQQc6YQZUo1EajQncWL

…ment under strict mode (#4683)

Fixes the 7 errors `presets/graphql-modules` hits once the root tsconfig
enables `strict: true`:

- builder.ts: `node.interfaces?.length > 0` compared a possibly-undefined
  value; default it to 0 (TS18048).
- index.ts: `Source.document` is optional, so skip sources without one
  before `concatAST`, matching core (TS2345).
- index.ts: `getConfigValue` infers `T` from the nullable input, so it
  returned `boolean | undefined`; use `?? true` for `useGraphQLModules`
  (TS2322).
- index.ts: `.filter(Boolean)` does not narrow `rootTypes`; use a
  `string` type guard (TS2322).
- utils.ts: `Source.location` is optional and `path.normalize(undefined)`
  throws, so skip sources without one in `groupSourcesByModule` (TS2345).

Generated output from the CLI is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XSMiQQc6YQZUo1EajQncWL

eddeee888:oss:issue-fix
@changeset-bot

changeset-bot Bot commented Sep 26, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 97f8cac

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

This PR includes changesets to release 2 packages
Name Type
@graphql-codegen/graphql-modules-preset Patch
@graphql-codegen/visitor-plugin-common 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 26, 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-20260926134248-97f8cac45b7bd618516db8d296fb3f4f8ac7f120 npm ↗︎ unpkg ↗︎
@graphql-codegen/add 7.1.1-alpha-20260926134248-97f8cac45b7bd618516db8d296fb3f4f8ac7f120 npm ↗︎ unpkg ↗︎
@graphql-codegen/visitor-plugin-common 7.2.6-alpha-20260926134248-97f8cac45b7bd618516db8d296fb3f4f8ac7f120 npm ↗︎ unpkg ↗︎
@graphql-codegen/typescript-document-nodes 6.1.1-alpha-20260926134248-97f8cac45b7bd618516db8d296fb3f4f8ac7f120 npm ↗︎ unpkg ↗︎
@graphql-codegen/graphql-modules-preset 6.1.1-alpha-20260926134248-97f8cac45b7bd618516db8d296fb3f4f8ac7f120 npm ↗︎ unpkg ↗︎
@graphql-codegen/testing 5.0.5-alpha-20260926134248-97f8cac45b7bd618516db8d296fb3f4f8ac7f120 npm ↗︎ unpkg ↗︎

Comment thread packages/presets/graphql-modules/src/index.ts Outdated
Comment thread packages/presets/graphql-modules/src/index.ts Outdated
…t when given a default (#4683)

`getConfigValue` inferred `T` from both arguments, so a nullable config
value made the result nullable even with a non-nullable default. Type
`value` as `T | null | undefined` so `T` comes from the default. Under
`strict: true` this fixes the two TS2345 errors in
base-documents-visitor.ts. With `strictNullChecks` off (current master)
the signature is unchanged.

graphql-modules goes back to `getConfigValue` for `useGraphQLModules`
instead of `?? true`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XSMiQQc6YQZUo1EajQncWL

eddeee888:oss:issue-fix
…4683)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XSMiQQc6YQZUo1EajQncWL

eddeee888:oss:issue-fix
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