-
#9449
4d9ea1a5a
Thanks @n1ru4l! - dependencies updates:- Updated dependency
@graphql-tools/utils@^10.0.0
↗︎ (from^9.0.0
, independencies
)
- Updated dependency
-
#9332
f46803a8c
Thanks @eddeee888! - Update GitHub loader TypeScript type and usage docs -
#9360
63827fabe
Thanks @beerose! - Add handleAsSDL property to UrlSchemaOptions type
-
#9151
b7dacb21f
Thanks @'./user/schema.mappers#UserMapper',! - AddwatchPattern
config option forgenerates
sections.By default,
watch
mode 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
generates
section now has awatchPattern
option 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.ts
files. We want to re-run Codegen if the content of*.mappers.ts
files 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
watch
mode:yarn graphql-codegen --watch
Now, updating
*.mappers.ts
files re-runs Codegen! 🎉Note:
watchPattern
is only used inwatch
mode i.e. running CLI with--watch
flag.
f104619ac
Thanks @saihaj! - Resolve issue with nesting fields in@provides
directive being prevented
-
#8893
a118c307a
Thanks @n1ru4l! - markplugins
in config optional -
#8723
a3309e63e
Thanks @kazekyo! - Introduce a new feature called DocumentTransform.DocumentTransform is a functionality that allows you to modify
documents
before they are processed by plugins. You can use functions passed to thedocumentTransforms
option to make changes to GraphQL documents.To use this feature, you can write
documentTransforms
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: [ { transform: ({ documents }) => { // Make some changes to the documents return documents; }, }, ], }, }, }; export default config;
For instance, to remove a
@localOnlyDirective
directive 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 config;
DocumentTransform 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;
- #8879
8206b268d
Thanks @renovate! - dependencies updates:- Updated dependency
tslib@~2.5.0
↗︎ (from~2.4.0
, independencies
)
- Updated dependency
-
#8771
ed87c782b
Thanks @renovate! - dependencies updates:- Updated dependency
@graphql-tools/utils@^9.0.0
↗︎ (from^8.8.0
, independencies
)
- Updated dependency
-
#8718
6c6b6f2df
Thanks @AaronBuxbaum! - AddglobalGqlIdentifierName
to the types
307a5d350
Thanks @saihaj! - Something went wrong in old relesae so this will ensure we have a good bump on all packages
- #8662
c0183810f
Thanks @jantimon! - the life cycle hook beforeOneFileWrite is now able to modify the generated content
-
#8686
a6c2097f4
Thanks @renovate! - dependencies updates:- Updated dependency
change-case-all@1.0.15
↗︎ (from1.0.14
, independencies
)
- Updated dependency
- #8525
63dc8f205
Thanks @charlypoly! - removeDetailledError
, not supported by Listr renderer
- #8368
4113b1bd3
Thanks @charlypoly! - fix(cli): support ApolloEngine loader in TypeScript config
- #8301
2ed21a471
Thanks @charlypoly! - Introduces support for TypeScript config file and a new preset lifecycle (required forclient-preset
)
- #8189
b408f8238
Thanks @n1ru4l! - Fix CommonJS TypeScript resolution withmoduleResolution
node16
ornodenext
- 6a2e328e6: feat(cli):
--verbose
and--debug
flags
-
2cbcbb371: Add new flag to emit legacy common js imports. Default it will be
true
this 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: true
Alternative you can use the CLI to set this option:
$ codegen --config-file=config.yml --emit-legacy-common-js-imports
-
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: true
Alternative you can use the CLI to set this option:
$ codegen --config-file=config.yml --ignore-no-documents
-
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:5
Only happens when TS compiler options
strictNullChecks: true
andskipLibCheck: false
.Partial<T>
includes{}
, thereforeNewVisitor[keyof NewVisitor]
includesundefined
, and indexingundefined
is error. Eliminateundefined
by wrapping it insideNonNullable<...>
.Related #7519
- a521216d6: broken links within documentation
- cb9adeb96: Cache validation of documents
- 754a33715: Performance Profiler --profile
- 6002feb3d: Fix exports in package.json files for react-native projects
- bcc5636fc: fix wrong dependency version range
- 97ddb487a: feat: GraphQL v16 compatibility
- 7c60e5acc: feat(core): ability to skip some specific validation rules with skipDocumentsValidation option
- 6470e6cc9: fix(plugin-helpers): remove unnecessary import
- 35199dedf: Fix module not found bug in resolveExternalModuleAndFn
- 39773f59b: enhance(plugins): use getDocumentNodeFromSchema and other utilities from @graphql-tools/utils
- 440172cfe: support ESM
- 24185985a: bump graphql-tools package versions
-
b0cb13df4: Update to latest
graphql-tools
andgraphql-config
version.‼️ ‼️ ‼️ 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.
- 470336a1: don't require plugins for for config if preset provides plugin. Instead the preset should throw if no plugins were provided.
- dfd25caf: chore(deps): bump graphql-tools versions
- 637338cb: fix: make lifecycle hooks definition a partial
- d9212aa0: fix(visitor-plugin-common): guard for a runtime type error
- 23862e7e: fix(naming-convention): revert and pin change-case-all dependency for workaround #3256
- 29b75b1e: enhance(namingConvention): use change-case-all instead of individual packages for naming convention
- 1183d173: Bump all packages to resolve issues with shared dependencies
- eaf45d1f: fix issue with inline fragment without typeCondition
- 857c603c: Adds the --errors-only flag to the cli to print errors only.
- da8bdd17: Allow hooks to be defined as partial object
- 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