Repository navigation
feat!: [@graphql-codegen/plugin-helpers] pass an info object to plugin validate (#11071) - #11100
Conversation
🦋 Changeset detectedLatest commit: b138519 The changes in this PR will be included in the next version bump. This PR includes changesets to release 18 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 |
|
📖 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)} |
There was a problem hiding this comment.
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 = { |
There was a problem hiding this comment.
Possible to type this or nah???
There was a problem hiding this comment.
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`` validateis aPluginValidateFnthat takesinfo: PluginInfo, so a dropped or mistyped field is already an error at that call. types.ts L743-L767- The
plugincall is checked more weakly, becausePluginFunction'sinfohas 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 (
PluginInfois 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
There was a problem hiding this comment.
Type it.
Arbitrary objects can take on extraneous fields. Typing allows cleanup if fields are removed. Make this a rule.
There was a problem hiding this comment.
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 () => { |
There was a problem hiding this comment.
Never mock that something is passed into function, this is just interface testing. Make a rule
There was a problem hiding this comment.
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
b7a5a3c to
a8bbbd0
Compare
validate (#11071)validate (#11071)
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
e835bd9 to
4efa1b7
Compare
There was a problem hiding this comment.
Is this a new file? If so, delete it, this way of testing only gives local confidence
There was a problem hiding this comment.
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
info with PluginInfo (#11071)
#11102
* 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>
Note
Opened on autopilot by Code Ops plugin;
Description
A plugin's
validatenow receives the same info object asplugin, instead of three extra positional arguments:@graphql-codegen/plugin-helpers: new exportedPluginInfotype;PluginValidateFntakes it as its fourth parameter.@graphql-codegen/core:executePluginbuilds oneinfoobject, annotated asPluginInfo, and passes it to bothvalidateandplugin. This removes theFIXMEabout syncing the two signatures.executePlugin'svalidatecatch no longer assumes anError: a thrown string or other non-Error value is reported as text instead ofundefined.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) thePluginValidateFngeneric now uses the plugin's own config type instead ofany;typed-document-nodealready used its config type.validate-configuration.mdxshows the new signature in its examples, adds a migration note and a callout thatpluginContextis the same context objectpluginreceives ininfo.majorchangeset covering core, plugin-helpers and the five plugins.This is a hard break with no compatibility shim, so custom plugins that export
validateand readoutputFile,allPluginsorpluginContextpositionally must destructure them from the fourth argument.pluginContextwas optional in the oldvalidatesignature and is now always provided, so it is required onPluginInfo.Relates to #11071
Type of change
Screenshots/Sandbox (if appropriate/relevant):
N/A (no UI change).
How Has This Been Tested?
pnpm vitest runin each package): core 1/1 (the existingprepend.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 lintandpnpm prettier:checkpass at the head commit.executePlugin's info passing or for its non-Errorcatchhandling. A spec for them was added and then removed in review, since that way of testing only gives local confidence. The newvalidatesignature is exercised only through the updatedfragment-matcherandschema-astspecs, which callvalidatewith the new four-argument shape, and through the other plugins' own suites.init.spec.tsfailures in the CLI package that also occur without this change; this was not verified independently.Test Environment:
@graphql-codegen/...: this branch (core,plugin-helpers,fragment-matcher,introspection,schema-ast,typescript-document-nodes,typed-document-node)Checklist:
fragment-matcherandschema-astspecs were updated to the new signature;executePluginhas no new dedicated test)Further comments
PluginInfo,outputFile,allPluginsandpluginContextare all required, becauseexecutePluginalways supplies them.PluginFunction's owninfotype is unchanged and still optional, so the two types differ slightly.PluginFunction'sinfowithPluginInfois deferred and tracked as T013 on #11071, to be picked up separately.executePluginnow passes the sameinfoobject reference to bothvalidateandplugin(previouslypluginreceived a fresh object literal), so avalidatethat mutatesinfowould be visible toplugin. No first-partyvalidatemutates it.catch (e: any)blocks in the fragment-matcher and schema-ast specs now have comments explaining whyanyis used. The schema-ast spec also passes{}instead ofnullas thevalidateconfig argument, becausevalidateis now typed withSchemaASTConfig.pluginContextkeepsany(a free-form bag shared between plugins), with a comment saying so.Generated by Claude Code