diff --git a/.changeset/beige-insects-try.md b/.changeset/beige-insects-try.md deleted file mode 100644 index 4d95b40ca11..00000000000 --- a/.changeset/beige-insects-try.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -'@graphql-codegen/visitor-plugin-common': patch -'@graphql-codegen/client-preset': patch ---- - -Fix fragment masking generation when conditional directive is used diff --git a/.changeset/famous-rats-laugh.md b/.changeset/famous-rats-laugh.md deleted file mode 100644 index dc37a673c05..00000000000 --- a/.changeset/famous-rats-laugh.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@graphql-codegen/typescript-operations': patch ---- - -Fix types when introspection is used and values are not generated or imported correctly diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ad9d8795768..f50bcd253e4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -178,7 +178,7 @@ jobs: name: Unit Test on Node ${{matrix.node_version}} (${{matrix.os}}) and GraphQL v${{matrix.graphql_version}} - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} needs: - lint - prettier-check @@ -189,7 +189,7 @@ jobs: node_version: [22, 24] graphql_version: [15, 16, 17] include: - - node-version: 22 + - node_version: 22 os: windows-latest graphql_version: 16 steps: @@ -223,7 +223,7 @@ jobs: name: Watcher Unit Test on Node ${{matrix.node_version}} (${{matrix.os}}) and GraphQL v${{matrix.graphql_version}} - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} needs: - lint - prettier-check @@ -234,7 +234,7 @@ jobs: node_version: [20] graphql_version: [15, 16] include: - - node-version: 20 + - node_version: 20 os: windows-latest graphql_version: 16 steps: diff --git a/packages/plugins/other/visitor-plugin-common/CHANGELOG.md b/packages/plugins/other/visitor-plugin-common/CHANGELOG.md index f241a1e0426..8a6c8d4f836 100644 --- a/packages/plugins/other/visitor-plugin-common/CHANGELOG.md +++ b/packages/plugins/other/visitor-plugin-common/CHANGELOG.md @@ -1,5 +1,14 @@ # @graphql-codegen/visitor-plugin-common +## 7.2.3 + +### Patch Changes + +- [#10904](https://github.com/dotansimha/graphql-code-generator/pull/10904) + [`2dd1531`](https://github.com/dotansimha/graphql-code-generator/commit/2dd1531475193de473cb5220926faf8715a64854) + Thanks [@eddeee888](https://github.com/eddeee888)! - Fix fragment masking generation when + conditional directive is used + ## 7.2.2 ### Patch Changes diff --git a/packages/plugins/other/visitor-plugin-common/package.json b/packages/plugins/other/visitor-plugin-common/package.json index 6b18f255dff..556d5d50384 100644 --- a/packages/plugins/other/visitor-plugin-common/package.json +++ b/packages/plugins/other/visitor-plugin-common/package.json @@ -1,6 +1,6 @@ { "name": "@graphql-codegen/visitor-plugin-common", - "version": "7.2.2", + "version": "7.2.3", "type": "module", "repository": { "type": "git", diff --git a/packages/plugins/typescript/operations/CHANGELOG.md b/packages/plugins/typescript/operations/CHANGELOG.md index 16cac79e86b..a86e63fd561 100644 --- a/packages/plugins/typescript/operations/CHANGELOG.md +++ b/packages/plugins/typescript/operations/CHANGELOG.md @@ -1,5 +1,36 @@ # @graphql-codegen/typescript-operations +## 6.1.5 + +### Patch Changes + +- [#10909](https://github.com/dotansimha/graphql-code-generator/pull/10909) + [`b36c084`](https://github.com/dotansimha/graphql-code-generator/commit/b36c0843de8d5f5958f1eabee74fd72086d63953) + Thanks [@jaydenseric](https://github.com/jaydenseric)! - Added missing types and tests for the + TypeScript operations plugin option `disableDescriptions`. + +## 6.1.4 + +### Patch Changes + +- [#10910](https://github.com/dotansimha/graphql-code-generator/pull/10910) + [`1624c8a`](https://github.com/dotansimha/graphql-code-generator/commit/1624c8aae53176a21c0dbbe1fb0d7d565ba50e22) + Thanks [@eddeee888](https://github.com/eddeee888)! - Fix performance issue when + config.importSchemaTypesFrom is set, and the provided schema is still unnecessarily visited + +## 6.1.3 + +### Patch Changes + +- [#10905](https://github.com/dotansimha/graphql-code-generator/pull/10905) + [`5a9f96c`](https://github.com/dotansimha/graphql-code-generator/commit/5a9f96cde55b310976729d5fc3cc2e7aa98ace31) + Thanks [@eddeee888](https://github.com/eddeee888)! - Fix types when introspection is used and + values are not generated or imported correctly + +- Updated dependencies + [[`2dd1531`](https://github.com/dotansimha/graphql-code-generator/commit/2dd1531475193de473cb5220926faf8715a64854)]: + - @graphql-codegen/visitor-plugin-common@7.2.3 + ## 6.1.2 ### Patch Changes diff --git a/packages/plugins/typescript/operations/package.json b/packages/plugins/typescript/operations/package.json index 157b48c4c4f..95f6b0d3591 100644 --- a/packages/plugins/typescript/operations/package.json +++ b/packages/plugins/typescript/operations/package.json @@ -1,6 +1,6 @@ { "name": "@graphql-codegen/typescript-operations", - "version": "6.1.2", + "version": "6.1.5", "type": "module", "description": "GraphQL Code Generator plugin for generating TypeScript types for GraphQL queries, mutations, subscriptions and fragments", "repository": { diff --git a/packages/plugins/typescript/operations/src/config.ts b/packages/plugins/typescript/operations/src/config.ts index eb2db30ad27..23d96183bc3 100644 --- a/packages/plugins/typescript/operations/src/config.ts +++ b/packages/plugins/typescript/operations/src/config.ts @@ -132,6 +132,32 @@ export interface TypeScriptDocumentsPluginConfig extends RawDocumentsConfig { * ``` */ noExport?: boolean; + + /** + * @description Set the value to `true` in order to disable all description generation. + * @default false + * + * @exampleMarkdown + * ## Disable description generation + * ```ts filename="codegen.ts" + * import type { CodegenConfig } from '@graphql-codegen/cli' + * + * const config: CodegenConfig = { + * // ... + * generates: { + * 'path/to/file.ts': { + * plugins: ['typescript-operations'], + * config: { + * disableDescriptions: true + * } + * } + * } + * } + * export default config + * ``` + */ + disableDescriptions?: boolean; + /** * @name addOperationExport * @type boolean diff --git a/packages/plugins/typescript/operations/src/index.ts b/packages/plugins/typescript/operations/src/index.ts index 393f5703df9..f2a1d59fce6 100644 --- a/packages/plugins/typescript/operations/src/index.ts +++ b/packages/plugins/typescript/operations/src/index.ts @@ -81,8 +81,16 @@ export const plugin: PluginFunction< // #region generateSchemaTypes // When Input and Enum appear in Result selection sets, we need to // generate those types so they can be referred to correctly - const schemaTypes = oldVisit(transformSchemaAST(schema, config).ast, { leave: visitor }); - const schemaTypesDefinitions = findTransformedDefinitions(schemaTypes); + // + // Note: we don't run visitor on the schema when i.e. `!config.importSchemaTypesFrom` + // because the schema types are supposedly already generated elsewhere. + // In such cases, running the visitor on the schema will do unncessary work + let schemaTypesDefinitions: string[] = []; + if (!config.importSchemaTypesFrom) { + const schemaTypes = oldVisit(transformSchemaAST(schema, config).ast, { leave: visitor }); + schemaTypesDefinitions = findTransformedDefinitions(schemaTypes); + } + // #endregion // #region generateIntrospectionTypesDefinitions diff --git a/packages/plugins/typescript/operations/tests/ts-documents.spec.ts b/packages/plugins/typescript/operations/tests/ts-documents.spec.ts index 1d98e92f2e5..262d82dcae4 100644 --- a/packages/plugins/typescript/operations/tests/ts-documents.spec.ts +++ b/packages/plugins/typescript/operations/tests/ts-documents.spec.ts @@ -48,6 +48,47 @@ describe('TypeScript Operations Plugin', () => { await validate(content); }); + describe('disableDescriptions', () => { + const description = 'Description.'; + const testSchema = buildSchema(/* GraphQL */ ` + "${description}" + enum A { + B + } + + type Query { + a: A + } + `); + const document = parse(/* GraphQL */ ` + query { + a + } + `); + + it('Should generate descriptions when set to false', async () => { + const { content } = await plugin( + testSchema, + [{ document }], + { disableDescriptions: false }, + { outputFile: '' }, + ); + + expect(content).toContain(description); + }); + + it('Should not generate descriptions when set to true', async () => { + const { content } = await plugin( + testSchema, + [{ document }], + { disableDescriptions: true }, + { outputFile: '' }, + ); + + expect(content).not.toContain(description); + }); + }); + it('Can merge an inline fragment with a spread', async () => { const testSchema = buildSchema(/* GraphQL */ ` interface Comment { diff --git a/packages/presets/client/CHANGELOG.md b/packages/presets/client/CHANGELOG.md index 547312e6e19..8736abc8c08 100644 --- a/packages/presets/client/CHANGELOG.md +++ b/packages/presets/client/CHANGELOG.md @@ -1,5 +1,20 @@ # @graphql-codegen/client-preset +## 6.1.1 + +### Patch Changes + +- [#10904](https://github.com/dotansimha/graphql-code-generator/pull/10904) + [`2dd1531`](https://github.com/dotansimha/graphql-code-generator/commit/2dd1531475193de473cb5220926faf8715a64854) + Thanks [@eddeee888](https://github.com/eddeee888)! - Fix fragment masking generation when + conditional directive is used + +- Updated dependencies + [[`2dd1531`](https://github.com/dotansimha/graphql-code-generator/commit/2dd1531475193de473cb5220926faf8715a64854), + [`5a9f96c`](https://github.com/dotansimha/graphql-code-generator/commit/5a9f96cde55b310976729d5fc3cc2e7aa98ace31)]: + - @graphql-codegen/visitor-plugin-common@7.2.3 + - @graphql-codegen/typescript-operations@6.1.3 + ## 6.1.0 ### Minor Changes diff --git a/packages/presets/client/package.json b/packages/presets/client/package.json index e169cf7de25..5b626be03ad 100644 --- a/packages/presets/client/package.json +++ b/packages/presets/client/package.json @@ -1,6 +1,6 @@ { "name": "@graphql-codegen/client-preset", - "version": "6.1.0", + "version": "6.1.1", "type": "module", "description": "GraphQL Code Generator preset for client.", "repository": {