Skip to content

feat!: [@graphql-codegen/plugin-helpers] pass an info object to plugin validate (#11071) - #11100

Merged
eddeee888 merged 2 commits into
master-nextfrom
feat/plugin-validate-info-object
Nov 3, 2026
Merged

eddeee888 merged 2 commits into
master-nextfrom
feat/plugin-validate-info-object

Conversation

@eddeee888

@eddeee888 eddeee888 commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

Note

Opened on autopilot by Code Ops plugin;

Description

A plugin's validate now receives the same info object as plugin, instead of three extra positional arguments:

// before
validate(schema, documents, config, outputFile, allPlugins, pluginContext);
// after
validate(schema, documents, config, { outputFile, allPlugins, pluginContext });
  • @graphql-codegen/plugin-helpers: new exported PluginInfo type; PluginValidateFn takes it as its fourth parameter.
  • @graphql-codegen/core: executePlugin builds one info object, annotated as PluginInfo, and passes it to both validate and plugin. This removes the FIXME about syncing the two signatures.
  • executePlugin's validate catch no longer assumes an Error: a thrown string or other non-Error value is reported as text instead of undefined.
  • First-party plugins with validate (fragment-matcher, introspection, schema-ast, typescript-document-nodes, typed-document-node) destructure what they need. In four of them (fragment-matcher, introspection, schema-ast, typescript-document-nodes) the PluginValidateFn generic now uses the plugin's own config type instead of any; typed-document-node already used its config type.
  • Docs: validate-configuration.mdx shows the new signature in its examples, adds a migration note and a callout that pluginContext is the same context object plugin receives in info.
  • One major changeset covering core, plugin-helpers and the five plugins.

This is a hard break with no compatibility shim, so custom plugins that export validate and read outputFile, allPlugins or pluginContext positionally must destructure them from the fourth argument. pluginContext was optional in the old validate signature and is now always provided, so it is required on PluginInfo.

Relates to #11071

Type of change

  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Screenshots/Sandbox (if appropriate/relevant):

N/A (no UI change).

How Has This Been Tested?

  • Per-package vitest passes at the head commit (pnpm vitest run in each package): core 1/1 (the existing prepend.spec.ts), fragment-matcher 16/16, introspection 3/3, schema-ast 11/11, typescript-document-nodes 11/11, typed-document-node 7/7.
  • pnpm types:check, pnpm lint and pnpm prettier:check pass at the head commit.
  • No dedicated test in this PR for executePlugin's info passing or for its non-Error catch handling. A spec for them was added and then removed in review, since that way of testing only gives local confidence. The new validate signature is exercised only through the updated fragment-matcher and schema-ast specs, which call validate with the new four-argument shape, and through the other plugins' own suites.
  • Not run in full: the whole CLI suite. The author reports 5 init.spec.ts failures in the CLI package that also occur without this change; this was not verified independently.

Test Environment:

  • OS: Linux
  • @graphql-codegen/...: this branch (core, plugin-helpers, fragment-matcher, introspection, schema-ast, typescript-document-nodes, typed-document-node)
  • NodeJS: 22.23.4
  • pnpm: 11.24.0

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works (existing fragment-matcher and schema-ast specs were updated to the new signature; executePlugin has no new dedicated test)
  • New and existing unit tests pass locally with my changes (the whole CLI suite was not run; see above)

Further comments

  • In PluginInfo, outputFile, allPlugins and pluginContext are all required, because executePlugin always supplies them. PluginFunction's own info type is unchanged and still optional, so the two types differ slightly.
  • The review suggestion to type PluginFunction's info with PluginInfo is deferred and tracked as T013 on #11071, to be picked up separately.
  • executePlugin now passes the same info object reference to both validate and plugin (previously plugin received a fresh object literal), so a validate that mutates info would be visible to plugin. No first-party validate mutates it.
  • The catch (e: any) blocks in the fragment-matcher and schema-ast specs now have comments explaining why any is used. The schema-ast spec also passes {} instead of null as the validate config argument, because validate is now typed with SchemaASTConfig.
  • pluginContext keeps any (a free-form bag shared between plugins), with a comment saying so.

Generated by Claude Code

@eddeee888 eddeee888 added the autopilot Experimental AI PRs label Nov 2, 2026 — with Claude
@changeset-bot

changeset-bot Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b138519

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

This PR includes changesets to release 18 packages
Name Type
@graphql-codegen/core Major
@graphql-codegen/plugin-helpers Major
@graphql-codegen/fragment-matcher Major
@graphql-codegen/introspection Major
@graphql-codegen/schema-ast Major
@graphql-codegen/typescript-document-nodes Major
@graphql-codegen/typed-document-node Major
@graphql-codegen/cli Patch
@graphql-codegen/gql-tag-operations Patch
@graphql-codegen/typescript-operations Patch
@graphql-codegen/typescript-resolvers Patch
@graphql-codegen/typescript Patch
@graphql-codegen/add Patch
@graphql-codegen/time Patch
@graphql-codegen/visitor-plugin-common Patch
@graphql-codegen/client-preset Patch
@graphql-codegen/graphql-modules-preset Patch
@graphql-codegen/testing 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

@eddeee888 eddeee888 self-assigned this Nov 2, 2026
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

📖 Docs preview (rebuilds on every push, ready ~10 min after each): https://codegen-pr-11100.guild-dev-website.pages.dev/graphql/codegen

throw new Error(
`Plugin "${options.name}" validation failed: \n
${e.message}
${e instanceof Error ? e.message : String(e)}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drive-by: Issue #11071 only asks to change what validate receives. This catch wraps the try that the PR rewrites, though. Before, it read e.message from an any, so a custom validate that runs throw 'bad extension' got reported as validation failed: undefined. Now a non-Error value is reported with String(e), and catch (e: any) is narrowed to catch (e). The new test reports a non-Error thrown by validate in packages/graphql-codegen-core/tests/execute-plugin.spec.ts covers this.

Skill: cops:pr-note


Generated by Claude Code

const documents = options.documents || [];
const pluginContext = options.pluginContext || {};
const profiler = options.profiler ?? createNoopProfiler();
const info = {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possible to type this or nah???

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, const info: PluginInfo = ... works, but it isn't needed: TypeScript already checks info at the validate call.

  • The inferred type already matches PluginInfo (outputFile: string, allPlugins: Types.ConfiguredPlugin[], pluginContext: { [key: string]: any }), so an annotation would not change inference. execute-plugin.ts L47-L51``
  • validate is a PluginValidateFn that takes info: PluginInfo, so a dropped or mistyped field is already an error at that call. types.ts L743-L767
  • The plugin call is checked more weakly, because PluginFunction's info has all-optional fields plus an index signature. A mistyped field still errors, but a dropped one does not. execute-plugin.ts L69-L78````
  • The annotation would add one import (PluginInfo is already re-exported from @graphql-codegen/plugin-helpers) and is a type TypeScript can infer, so I left it off. index.ts L7-L8

Say if you'd like : PluginInfo added so the error shows up at the declaration instead.

Skill: cops:pr-address


Generated by Claude Code

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type it.

Arbitrary objects can take on extraneous fields. Typing allows cleanup if fields are removed. Make this a rule.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in e835bd9: info is now const info: PluginInfo = { ... }, with PluginInfo added to the existing @graphql-codegen/plugin-helpers import. A removed or renamed PluginInfo field is now a type error where the object is created.

Skill: cops:pr-address · Approved: eddeee888


Generated by Claude Code

import { executePlugin } from '../src/execute-plugin.js';

describe('executePlugin', () => {
it('passes outputFile, allPlugins and pluginContext to validate', async () => {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mock that something is passed into function, this is just interface testing. Make a rule

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 550c19a, 40471e7 and b7a5a3c: the mocked validate assertion is replaced with behavior tests. One uses a validate that rejects a disallowed output file only when it is the only plugin, and asserts executePlugin rejects with one plugin and resolves with two. The unneeded ?. on non-nullable values is removed.

Skill: cops:pr-address · Approved: eddeee888


Generated by Claude Code

@eddeee888 eddeee888 mentioned this pull request Nov 2, 2026
13 tasks done
@eddeee888
eddeee888 force-pushed the feat/plugin-validate-info-object branch from b7a5a3c to a8bbbd0 Compare November 3, 2026 07:31
@eddeee888 eddeee888 changed the title feat!: pass an info object to plugin validate (#11071) feat!: [@graphql-codegen/plugin-helpers] pass an info object to plugin validate (#11071) Nov 3, 2026
A plugin's validate now receives the same info object as plugin,
validate(schema, documents, config, { outputFile, allPlugins, pluginContext }),
instead of three extra positional arguments. This removes the FIXME about
syncing the two signatures.

- plugin-helpers: new exported PluginInfo type; PluginValidateFn takes it as its fourth parameter.
- core: executePlugin builds one info object, annotated as PluginInfo, for validate and plugin, and reports non-Error values thrown by validate as text.
- first-party plugins with validate destructure what they need and type validate with their own config type.
- docs and a major changeset describe the breaking change.
- tests assert validate's observable behavior.

Skill: cops:pr-start
Approved-by: eddeee888

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NyYayAjomYW7WkBHoQichg
@eddeee888
eddeee888 force-pushed the feat/plugin-validate-info-object branch from e835bd9 to 4efa1b7 Compare November 3, 2026 08:04

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a new file? If so, delete it, this way of testing only gives local confidence

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it was a new file in this PR (116 lines, 3 tests). Deleted in b138519; nothing else referenced it.

Skill: cops:pr-address · Approved: eddeee888


Generated by Claude Code


Generated by Claude Code

Argument-and-behavior tests of executePlugin in isolation only give local confidence.

Skill: cops:pr-address
Approved-by: eddeee888

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NyYayAjomYW7WkBHoQichg
@eddeee888
eddeee888 marked this pull request as ready for review November 3, 2026 08:20
@eddeee888
eddeee888 merged commit 20b5c3d into master-next Nov 3, 2026
1 check passed
@eddeee888
eddeee888 deleted the feat/plugin-validate-info-object branch November 3, 2026 08:21
eddeee888 added a commit that referenced this pull request Nov 7, 2026
* Dummy commit for next major

* refactor: [@graphql-codegen/cli] type generate() return as FileOutput[] | void (#11071) (#11074)

* refactor: type generate() return as FileOutput[] | void

The return was typed `FileOutput[] | any`, which collapsed to `any` and lost type-hints. Watch mode resolves with no value, so the union is `FileOutput[] | void`.

Skill: cops:pr-start
Approved-by: eddeee888

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

* refactor: note type-safety-only fallbacks in generate specs

The `|| []` and `?.` in the generate specs only satisfy the `void` return type, so each site now says so.

Skill: cops:pr-start
Approved-by: eddeee888

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>

* chore: remove deprecated emitLegacyCommonJSImports option (#11071) (#11078)

* chore: remove deprecated emitLegacyCommonJSImports option

`importExtension` replaces it, so the option, its CLI flag and every pass-through are dropped for the next major (#11071).

Skill: cops:pr-start
Approved-by: eddeee888
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WmgeFRnsoawCS9eR6uBjn8

* refactor: inline normalizeImportExtension

With emitLegacyCommonJSImports gone the helper only returns importExtension ?? '', so call sites use that directly and the export is removed.

Skill: cops:pr-start
Approved-by: eddeee888
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WmgeFRnsoawCS9eR6uBjn8

* refactor: default importExtension in plugin param destructure

Removes the redundant `?? ''` const by defaulting at the destructure.

Skill: cops:pr-address
Approved-by: eddeee888
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WmgeFRnsoawCS9eR6uBjn8

* refactor: reuse normalised importExtension in client-side visitor

BaseVisitor already defaults importExtension to '', so the extra `?? ''` is redundant.

Skill: cops:pr-address
Approved-by: eddeee888
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WmgeFRnsoawCS9eR6uBjn8

---------

Co-authored-by: Claude <noreply@anthropic.com>

* chore(dependencies): updated changesets for modified dependencies

* fix: [@graphql-codegen/plugin-helpers] `config.generates` takes `ConfiguredOutput[]` instead of `ConfiguredPlugin[]` (#11087)

* Stop exposing isOutputConfigArray and isConfiguredOutput

* Fix config.generates type

* Add more details to changeset

* Fix undefined case

* Add @graphql-codegen/cli to changeset as its interface changes because plugin-helpers changed

* Only warn once in watcher

* Add tests for array `generates` values in executeCodegen

Cover single-element, multi-element (first used, warns once), empty
array, and non-object element (old plugin-list shape) cases.

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

* Remove watcher warn about config

* Move array `generates` tests to codegen.generates.spec.ts

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

* Add tests for multiple entries and only warn once

* Update changeset to match final behavior

Fix typos and describe the cli warning, the return type change of
normalizeOutputParam and the empty array error.

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

* Clarify changeset wording on the old array behavior and error message

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

---------

Co-authored-by: Claude <noreply@anthropic.com>

* chore(dependencies): updated changesets for modified dependencies

* docs: update graphql peer range in custom plugin guide (#11086)

* chore: re-apply @graphql-tools majors and drop Node below 22.18 and graphql below 16 (lost from master-next, #11084) (#11090)

* chore(dependencies): updated changesets for modified dependencies

* test: remove dead graphql 15 test branches (#11092)

* chore: remove unused @graphql-tools/utils dependency (#11093)

* chore(dependencies): updated changesets for modified dependencies

* chore: [@graphql-codegen/plugin-helpers] declare apollo-engine-loader as a dependency (#11094)

* chore(dependencies): updated changesets for modified dependencies

* feat: [@graphql-codegen/schema-ast] remove no-op commentDescriptions option (#11071) (#11095)

* feat!: [@graphql-codegen/plugin-helpers] pass an info object to plugin `validate` (#11071) (#11100)

* refactor: [@graphql-codegen/plugin-helpers] type PluginFunction `info` with PluginInfo (#11071) (#11102)

* refactor: [@graphql-codegen/plugin-helpers] type PluginFunction `info` with PluginInfo

`plugin` and `validate` now share one info definition; the index signature stays for third-party plugins.

Skill: cops:pr-start
Approved-by: eddeee888
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NyYayDM9pv2k12dnZ8W44m

* refactor: [@graphql-codegen/plugin-helpers] reword PluginFunction info comment

Comment now describes only what the index signature does, not change history.

Skill: cops:pr-address
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NyYayDM9pv2k12dnZ8W44m

---------

Co-authored-by: Claude <noreply@anthropic.com>

* test: skip typescript-graphql-files-modules dev-test output with FIXME (#11108)

The published plugin still uses the old positional validate signature, which breaks with the new validate info object (#11071).


Claude-Session: https://claude.ai/code/session_01NyYayCpxtJ1D7KtvhxTPTV

Co-authored-by: Claude <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autopilot Experimental AI PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants