From 02d487c8c7a8e55da31b43fcb30d48615bc33950 Mon Sep 17 00:00:00 2001 From: Saihajpreet Singh Date: Mon, 25 Sep 2023 12:32:05 -0400 Subject: [PATCH] fix(preset/near-operation-file): accept skipDocumentsValidat (#414) * Revert "Revert "fix(preset/near-operation-file): accept skipDocumentsValidation config parameter. Closes #214 (#383)" (#413)" This reverts commit 5739a0ea872a2165ca3b9a9cc70d76c11be686a6. * fix(preset/near-operation-file): read skipDocumentsValidation from config (#409) * fix(preset/near-operation-file): add skipDocumentsValidation presetConfig types * Create brave-bulldogs-explode.md * fix(preset/near-operation-file): read skipDocumentsValidation from config * Update brave-bulldogs-explode.md * Delete .changeset/brave-bulldogs-explode.md --------- Co-authored-by: Herman Bilous --- .changeset/thirty-books-explode.md | 12 ++++++ .../presets/near-operation-file/src/index.ts | 6 ++- .../tests/near-operation-file.spec.ts | 42 ++++++++++++++++++- 3 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 .changeset/thirty-books-explode.md diff --git a/.changeset/thirty-books-explode.md b/.changeset/thirty-books-explode.md new file mode 100644 index 000000000..f2c470e6f --- /dev/null +++ b/.changeset/thirty-books-explode.md @@ -0,0 +1,12 @@ +--- +'@graphql-codegen/near-operation-file-preset': major +--- + +accept skipDocumentsValidation config parameter + +‼️ ‼️ ‼️ Please note ‼️ ‼️ ‼️: + +This is a breaking change since previous versions skips all documents validation +and this could raise validation errors while generating types. + + diff --git a/packages/presets/near-operation-file/src/index.ts b/packages/presets/near-operation-file/src/index.ts index c9dd7729a..859110f1e 100644 --- a/packages/presets/near-operation-file/src/index.ts +++ b/packages/presets/near-operation-file/src/index.ts @@ -343,6 +343,7 @@ export const preset: Types.OutputPreset = { } artifacts.push({ + ...options, filename, documents: [combinedSource], plugins, @@ -350,7 +351,10 @@ export const preset: Types.OutputPreset = { config, schema: options.schema, schemaAst: schemaObject, - skipDocumentsValidation: true, + skipDocumentsValidation: + typeof options.config.skipDocumentsValidation === 'undefined' + ? { skipDuplicateValidation: true } + : options.config.skipDocumentsValidation, }); } diff --git a/packages/presets/near-operation-file/tests/near-operation-file.spec.ts b/packages/presets/near-operation-file/tests/near-operation-file.spec.ts index e2b5f50f3..955e7e9ee 100644 --- a/packages/presets/near-operation-file/tests/near-operation-file.spec.ts +++ b/packages/presets/near-operation-file/tests/near-operation-file.spec.ts @@ -699,7 +699,47 @@ describe('near-operation-file preset', () => { pluginMap: {}, }); - expect(result[0].skipDocumentsValidation).toBeTruthy(); + expect(result[0].skipDocumentsValidation).toEqual({ skipDuplicateValidation: true }); + }); + + it('Should allow to customize the skip documents validation', async () => { + const result = await executePreset({ + baseOutputDir: './src/', + config: { + skipDocumentsValidation: { + skipValidationAgainstSchema: true, + }, + }, + presetConfig: { + baseTypesPath: 'types.ts', + }, + schema: schemaDocumentNode, + schemaAst: schemaNode, + documents: testDocuments, + plugins: [], + pluginMap: {}, + }); + + expect(result[0].skipDocumentsValidation).toEqual({ skipValidationAgainstSchema: true }); + }); + + it('Should allow to opt-out skipping documents validation', async () => { + const result = await executePreset({ + baseOutputDir: './src/', + config: { + skipDocumentsValidation: false, + }, + presetConfig: { + baseTypesPath: 'types.ts', + }, + schema: schemaDocumentNode, + schemaAst: schemaNode, + documents: testDocuments, + plugins: [], + pluginMap: {}, + }); + + expect(result[0].skipDocumentsValidation).toBe(false); }); it('Should allow to customize output extension', async () => {