@graphql-codegen/plugin-helpers
Changelog for @graphql-codegen/plugin-helpers: every release with its changes and the pull requests behind them.
7.3.0
Minor Changes
-
#10928
90229a5Thanks @eddeee888! - AddcontentComparison?: 'cache-first' | 'disk'to control disk-vs-cache write comparison in watch mode.In watch mode the CLI caches the hash of the content it last wrote per file and compares new output against that cached hash to skip redundant writes. This assumes generated output is a pure function of the codegen inputs. An output whose content depends on the file’s existing content (e.g. a preset that reads the file and rewrites part of it) breaks that assumption: if the file is changed on disk and codegen regenerates content identical to a previous run, the cached hash still matches and the write is skipped, so the on-disk change is never corrected.
contentComparison: 'disk'opts an output into comparing the generated content against the file on disk instead of the in-memory record of what codegen last wrote, so the file is rewritten when it was changed externally. It can be set:- by a preset, on the
GenerateOptionsit returns frombuildGeneratesSection, or - on the output config (
generates[output].contentComparison) for any output, including plain plugin outputs without a preset.
When both are present, the preset’s value takes precedence. The default,
'cache-first', keeps the existing in-memory-cache behaviour for outputs that are a pure function of their inputs. - by a preset, on the
Patch Changes
-
#10930
448431aThanks @eddeee888! - Fixoverwritebeing ignored for preset-basedgeneratesoutputs.A
generatesentry that used a preset and setoverwrite(e.g.overwrite: { removeStaleFiles: false }) had that setting silently ignored, so in watch mode its generated files could still be deleted as stale.The CLI resolved
overwriteper generated file by looking the file’s path up inconfig.generates. That fails for a preset: itsgeneratesentry is keyed by the preset’sbaseOutputDir, not by any generated file’s path (and a preset can emit files outside that directory), and the lookup additionally required apluginskey that preset entries don’t have. Both cases fell through to the globalconfig.overwrite(defaulttrue).
7.2.1
Patch Changes
-
#10924
0c8f5baThanks @eddeee888! - Fix profiler output not being written to the filesystem in watch mode (--profile --watch)The profiler trace was only written on the non-watch code path, after the watch-mode early return, so a profiled watch session never produced a
codegen-*.jsonfile.The profiler now writes a fresh trace file after the initial run and after every rebuild, with each file containing only that run’s events. A failed rebuild does not produce a trace and its events are discarded so they don’t leak into the next successful run.
The
Profilernow owns its own trace lifecycle:- a new
clear()method starts a new trace - a new
outputNameproperty provides the filename for the current trace (nullfor the noop profiler) - filename generation was removed from
CodegenContext
- a new
7.2.0
Minor Changes
-
#10921
58cdb31Thanks @eddeee888! - Extendoverwritewithoverwrite.removeStaleFilesandoverwrite.updateExistingFilesoverwritewas being used to both remove stale files in watch mode and update existing files. Some plugins such as Server Preset may dynamically return files to write between watch runs (for performance purposes).The
overwritecan now take an object withoverwrite.removeStaleFilesandoverwrite.updateExistingFilesfields to allow granular control over actions.This is not a breaking change because
overwrite=true|falsestill works.
7.1.0
Minor Changes
- #10866
959915fThanks @eddeee888! - dependencies updates:- Updated dependency
@graphql-tools/utils@^11.2.0↗︎ (from^11.0.0, independencies) - Updated dependency
graphql@^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0↗︎ (from^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0, inpeerDependencies)
- Updated dependency
7.0.1
Patch Changes
- #10797
6ed420aThanks @eddeee888! - Fix FederationTypes not having typesPrefix and typesSuffix applied
7.0.0
Major Changes
-
#10496
afaace6Thanks @eddeee888! - BREAKING CHANGE: Update deps to latest, some only support ESMNode 20 support is dropped in this release. Node 22 comes with
require()support for ESM, which means it’s easier to integrate ES modules into applications. Therefore, it is safe to start using ESM-only packages.If you are a user, please upgrade to Node 22. If you are a lib maintainer and see ESM vs CJS issues when running Jest tests, try using Vitest.
-
#10496
afaace6Thanks @eddeee888! - BREAKING CHANGE: Drop Node 20 support
Patch Changes
-
#10496
afaace6Thanks @eddeee888! - dependencies updates:- Updated dependency
change-case-all@^2.1.0↗︎ (from1.0.15, independencies)
- Updated dependency
-
#10496
afaace6Thanks @eddeee888! - dependencies updates:- Updated dependency
change-case-all@^2.1.0↗︎ (from1.0.15, independencies)
- Updated dependency
6.3.0
Minor Changes
-
#10659
e65d303Thanks @ikusakov2! - Add support forexternalDocumentsexternalDocumentsdeclares GraphQL documents that will be read but will not have type files generated for them. These documents are available to plugins for type resolution (e.g. fragment types), but no output files will be generated based on them. Accepts the same formats asdocuments.This config option is useful for monorepos where each project may want to generate types for its own documents, but some may need to read shared fragments from across projects.
Patch Changes
- #10103
9a66574Thanks @renovate! - dependencies updates:- Updated dependency
tslib@^2.8.0↗︎ (from~2.6.0, independencies)
- Updated dependency
6.2.1
Patch Changes
- #10661
2041865Thanks @dargmuesli! - Remove lodash.
6.2.0
Minor Changes
- #10617
8c4db2aThanks @ikusakov2! - Allow GraphQLSchema to be passed directly to generate({schema: …}) function
6.1.1
Patch Changes
- #10619
cdf5dc5Thanks @ardatan! - dependencies updates:- Updated dependency
@graphql-tools/utils@^11.0.0↗︎ (from^10.0.0, independencies)
- Updated dependency
6.1.0
Minor Changes
- #10510
9e70bcbThanks @nickmessing! - add importExtension configuration option
6.0.0
Major Changes
-
#10218
140298aThanks @eddeee888! - BREAKING CHANGES: Do not generate __isTypeOf for non-implementing types or non-union members -
#10218
140298aThanks @eddeee888! - Remove deprecated optionwatchConfig -
#10218
140298aThanks @eddeee888! - Ensure Federation Interfaces have__resolveReferenceif they are resolvable entitiesBREAKING CHANGES: Deprecate
onlyResolveTypeForInterfacesbecause majority of use cases cannot implement resolvers in Interfaces. BREAKING CHANGES: DeprecategenerateInternalResolversIfNeeded.__resolveReferencebecause types do not have__resolveReferenceif they are not Federation entities or are not resolvable. Users should not have to manually set this option. This option was put in to wait for this major version. -
#10218
140298aThanks @eddeee888! - BREAKING CHANGE: Improve Federation Entity’s resolvers’ parent param type: These types were using reference types inline. This makes it hard to handle mappers. The Parent type now all comes from ParentResolverTypes to make handling mappers and parent types simpler. -
#10218
140298aThanks @eddeee888! - Fixmappersusage with Federationmapperswas previously used as__resolveReference’s first param (usually called “reference”). However, this is incorrect becausereferenceinterface comes directly from@keyand@requiresdirectives. This patch fixes the issue by creating a newFederationTypestype and use it as the base for federation entity types when being used to type entity references.BREAKING CHANGES: No longer generate
UnwrappedObjectutility type, as this was used to support the wrong previously generated type. -
#10218
140298aThanks @eddeee888! - Drop Node 18 support
Minor Changes
- #10218
140298aThanks @eddeee888! - AddallowPartialOutputsflag to partially write successful generation to files
Patch Changes
-
#10218
140298aThanks @eddeee888! - Update @requires type -
#10218
140298aThanks @eddeee888! - Fix fields or object types marked with @external being wrongly generated
5.1.1
Patch Changes
- #10150
e324382Thanks @ArminWiebigke! - Allow functions to be passed as valid values forUrlSchemaOptions.customFetch. This was already possible, but the type definitions did not reflect that correctly.
5.1.0
Minor Changes
-
#9989
55a1e9eThanks @eddeee888! - AddgenerateInternalResolversIfNeededoptionThis option can be used to generate more correct types for internal resolvers. For example, only generate
__resolveReferenceif the federation object has a resolvable@key.In the future, this option can be extended to support other internal resolvers e.g.
__isTypeOfis only generated for implementing types and union members.
5.0.4
Patch Changes
- #9961
dfc5310Thanks @eddeee888! - Update plugin output type to allow optionmetafield
5.0.3
Patch Changes
5.0.2
Patch Changes
- #9811
d8364e045Thanks @saihaj! - dependencies updates:- Updated dependency
tslib@~2.6.0↗︎ (from~2.5.0, independencies)
- Updated dependency
5.0.1
Patch Changes
5.0.0
Major Changes
Patch Changes
-
#9449
4d9ea1a5aThanks @n1ru4l! - dependencies updates:- Updated dependency
@graphql-tools/utils@^10.0.0↗︎ (from^9.0.0, independencies)
- Updated dependency
-
#9332
f46803a8cThanks @eddeee888! - Update GitHub loader TypeScript type and usage docs -
#9360
63827fabeThanks @beerose! - Add handleAsSDL property to UrlSchemaOptions type
4.2.0
Minor Changes
-
#9151
b7dacb21fThanks @’./user/schema.mappers#UserMapper’,! - AddwatchPatternconfig option forgeneratessections.By default,
watchmode automatically watches all GraphQL schema and document files. This means when a change is detected, Codegen CLI is run.A user may want to run Codegen CLI when non-schema and non-document files are changed. Each
generatessection now has awatchPatternoption to allow more file patterns to be added to the list of patterns to watch.In the example below, mappers are exported from
schema.mappers.tsfiles. We want to re-run Codegen if the content of*.mappers.tsfiles change because they change the generated types file. To solve this, we can add mapper file patterns to watch using the glob pattern used for schema and document files.// codegen.ts const config: CodegenConfig = { schema: 'src/schema/**/*.graphql', generates: { 'src/schema/types.ts': { plugins: ['typescript', 'typescript-resolvers'], config: { mappers: { Book: './book/schema.mappers#BookMapper', }, } watchPattern: 'src/schema/**/*.mappers.ts', // Watches mapper files in `watch` mode. Use an array for multiple patterns e.g. `['src/*.pattern1.ts','src/*.pattern2.ts']` }, }, };Then, run Codegen CLI in
watchmode:pnpm graphql-codegen --watchNow, updating
*.mappers.tsfiles re-runs Codegen! 🎉Note:
watchPatternis only used inwatchmode i.e. running CLI with--watchflag.
Patch Changes
f104619acThanks @saihaj! - Resolve issue with nesting fields in@providesdirective being prevented
4.1.0
Minor Changes
-
#8893
a118c307aThanks @n1ru4l! - markpluginsin config optional -
#8723
a3309e63eThanks @kazekyo! - Introduce a new feature called DocumentTransform.DocumentTransform is a functionality that allows you to modify
documentsbefore they are processed by plugins. You can use functions passed to thedocumentTransformsoption to make changes to GraphQL documents.To use this feature, you can write
documentTransformsas follows:import type { CodegenConfig } from '@graphql-codegen/cli' const config: CodegenConfig = { schema: 'https://localhost:4000/graphql', documents: ['src/**/*.tsx'], generates: { './src/gql/': { preset: 'client', documentTransforms: [ { transform: ({ documents }) => { // Make some changes to the documents return documents } } ] } } } export default configFor instance, to remove a
@localOnlyDirectivedirective fromdocuments, you can write the following code:import type { CodegenConfig } from '@graphql-codegen/cli' import { visit } from 'graphql' const config: CodegenConfig = { schema: 'https://localhost:4000/graphql', documents: ['src/**/*.tsx'], generates: { './src/gql/': { preset: 'client', documentTransforms: [ { transform: ({ documents }) => { return documents.map(documentFile => { documentFile.document = visit(documentFile.document, { Directive: { leave(node) { if (node.name.value === 'localOnlyDirective') return null } } }) return documentFile }) } } ] } } } export default configDocumentTransform can also be specified by file name. You can create a custom file for a specific transformation and pass it to
documentTransforms.Let’s create the document transform as a file:
module.exports = { transform: ({ documents }) => { // Make some changes to the documents return documents } }Then, you can specify the file name as follows:
import type { CodegenConfig } from '@graphql-codegen/cli' const config: CodegenConfig = { schema: 'https://localhost:4000/graphql', documents: ['src/**/*.tsx'], generates: { './src/gql/': { preset: 'client', documentTransforms: ['./my-document-transform.js'] } } } export default config
Patch Changes
- #8879
8206b268dThanks @renovate! - dependencies updates:- Updated dependency
tslib@~2.5.0↗︎ (from~2.4.0, independencies)
- Updated dependency
4.0.0
Major Changes
Patch Changes
3.1.2
Patch Changes
-
#8771
ed87c782bThanks @renovate! - dependencies updates:- Updated dependency
@graphql-tools/utils@^9.0.0↗︎ (from^8.8.0, independencies)
- Updated dependency
-
#8718
6c6b6f2dfThanks @AaronBuxbaum! - AddglobalGqlIdentifierNameto the types
3.1.1
Patch Changes
307a5d350Thanks @saihaj! - Something went wrong in old relesae so this will ensure we have a good bump on all packages
3.1.0
Minor Changes
- #8662
c0183810fThanks @jantimon! - the life cycle hook beforeOneFileWrite is now able to modify the generated content
3.0.0
Major Changes
Patch Changes
-
#8686
a6c2097f4Thanks @renovate! - dependencies updates:- Updated dependency
change-case-all@1.0.15↗︎ (from1.0.14, independencies)
- Updated dependency
2.7.2
Patch Changes
- #8525
63dc8f205Thanks @charlypoly! - removeDetailledError, not supported by Listr renderer
2.7.1
Patch Changes
- #8368
4113b1bd3Thanks @charlypoly! - fix(cli): support ApolloEngine loader in TypeScript config
2.7.0
Minor Changes
- #8301
2ed21a471Thanks @charlypoly! - Introduces support for TypeScript config file and a new preset lifecycle (required forclient-preset)
2.6.2
Patch Changes
- #8189
b408f8238Thanks @n1ru4l! - Fix CommonJS TypeScript resolution withmoduleResolutionnode16ornodenext
2.6.1
Patch Changes
- 6a2e328e6: feat(cli):
--verboseand--debugflags
2.6.0
Minor Changes
-
2cbcbb371: Add new flag to emit legacy common js imports. Default it will be
truethis way it ensure that generated code works with non-compliant bundlers.You can use the option in your config:
schema: 'schema.graphql' documents: - 'src/**/*.graphql' emitLegacyCommonJSImports: trueAlternative you can use the CLI to set this option:
$ codegen --config-file=config.yml --emit-legacy-common-js-imports
2.5.0
Minor Changes
-
d84afec09: Support TypeScript ESM modules (
"module": "node16"and"moduleResolution": "node16"). -
8e44df58b: Add new config option to not exit with non-zero exit code when there are no documents.
You can use this option in your config:
schema: 'schema.graphql' documents: - 'src/**/*.graphql' ignoreNoDocuments: trueAlternative you can use the CLI to set this option:
$ codegen --config-file=config.yml --ignore-no-documents
Patch Changes
-
a4fe5006b: Fix TS type error on strictNullChecks: true
Fix the compiler error:
node_modules/@graphql-codegen/plugin-helpers/oldVisit.d.ts:5:75 - error TS2339: Property 'enter' does not exist on type '{ readonly enter?: ASTVisitFn<NameNode> | undefined; readonly leave: ASTReducerFn<NameNode, unknown>; } | { readonly enter?: ASTVisitFn<DocumentNode> | undefined; readonly leave: ASTReducerFn<...>; } | ... 41 more ... | undefined'. 5 enter?: Partial<Record<keyof NewVisitor, NewVisitor[keyof NewVisitor]['enter']>>; ~~~~~~~ node_modules/@graphql-codegen/plugin-helpers/oldVisit.d.ts:6:75 - error TS2339: Property 'leave' does not exist on type '{ readonly enter?: ASTVisitFn<NameNode> | undefined; readonly leave: ASTReducerFn<NameNode, unknown>; } | { readonly enter?: ASTVisitFn<DocumentNode> | undefined; readonly leave: ASTReducerFn<...>; } | ... 41 more ... | undefined'. 6 leave?: Partial<Record<keyof NewVisitor, NewVisitor[keyof NewVisitor]['leave']>>; ~~~~~~~ Found 2 errors in the same file, starting at: node_modules/@graphql-codegen/plugin-helpers/oldVisit.d.ts:5Only happens when TS compiler options
strictNullChecks: trueandskipLibCheck: false.Partial<T>includes{}, thereforeNewVisitor[keyof NewVisitor]includesundefined, and indexingundefinedis error. Eliminateundefinedby wrapping it insideNonNullable<...>.Related #7519
2.4.2
Patch Changes
- a521216d6: broken links within documentation
2.4.1
Patch Changes
- cb9adeb96: Cache validation of documents
2.4.0
Minor Changes
- 754a33715: Performance Profiler —profile
2.3.2
Patch Changes
- 6002feb3d: Fix exports in package.json files for react-native projects
2.3.1
Patch Changes
- bcc5636fc: fix wrong dependency version range
2.3.0
Minor Changes
- 97ddb487a: feat: GraphQL v16 compatibility
2.2.0
Minor Changes
- 7c60e5acc: feat(core): ability to skip some specific validation rules with skipDocumentsValidation option
2.1.1
Patch Changes
- 6470e6cc9: fix(plugin-helpers): remove unnecessary import
- 35199dedf: Fix module not found bug in resolveExternalModuleAndFn
2.1.0
Minor Changes
- 39773f59b: enhance(plugins): use getDocumentNodeFromSchema and other utilities from @graphql-tools/utils
- 440172cfe: support ESM
Patch Changes
- 24185985a: bump graphql-tools package versions
2.0.0
Major Changes
-
b0cb13df4: Update to latest
graphql-toolsandgraphql-configversion.‼️ ‼️ ‼️ Please note ‼️ ‼️ ‼️:
This is a breaking change since Node 10 is no longer supported in
graphql-tools, and also no longer supported for Codegen packages.
1.18.8
Patch Changes
- 470336a1: don’t require plugins for for config if preset provides plugin. Instead the preset should throw if no plugins were provided.
1.18.7
Patch Changes
- dfd25caf: chore(deps): bump graphql-tools versions
1.18.6
Patch Changes
- 637338cb: fix: make lifecycle hooks definition a partial
1.18.5
Patch Changes
- d9212aa0: fix(visitor-plugin-common): guard for a runtime type error
1.18.4
Patch Changes
- 23862e7e: fix(naming-convention): revert and pin change-case-all dependency for workaround #3256
1.18.3
Patch Changes
- 29b75b1e: enhance(namingConvention): use change-case-all instead of individual packages for naming convention
1.18.2
Patch Changes
- 1183d173: Bump all packages to resolve issues with shared dependencies
1.18.1
Patch Changes
- eaf45d1f: fix issue with inline fragment without typeCondition
1.18.0
Minor Changes
- 857c603c: Adds the —errors-only flag to the cli to print errors only.
1.17.9
Patch Changes
- da8bdd17: Allow hooks to be defined as partial object
1.17.8
Patch Changes
- 1d7c6432: Bump all packages to allow ”^” in deps and fix compatibility issues
- 1d7c6432: Bump versions of @graphql-tools/ packages to fix issues with loading schemas and SDL comments