diff --git a/.changeset/bright-islands-pretend.md b/.changeset/bright-islands-pretend.md new file mode 100644 index 00000000000..98531f617ea --- /dev/null +++ b/.changeset/bright-islands-pretend.md @@ -0,0 +1,7 @@ +--- +'@graphql-codegen/cli': minor +'@graphql-codegen/client-preset': minor +'@graphql-codegen/gql-tag-operations-preset': minor +--- + +It is no longer mandatory to declare an empty plugins array when using a preset diff --git a/.changeset/chilly-beers-sleep.md b/.changeset/chilly-beers-sleep.md new file mode 100644 index 00000000000..fd9ca78042b --- /dev/null +++ b/.changeset/chilly-beers-sleep.md @@ -0,0 +1,5 @@ +--- +'@graphql-codegen/plugin-helpers': minor +--- + +mark `plugins` in config optional diff --git a/dev-test/codegen.ts b/dev-test/codegen.ts index 638af593259..29c4b79cc94 100644 --- a/dev-test/codegen.ts +++ b/dev-test/codegen.ts @@ -189,34 +189,29 @@ const config: CodegenConfig = { schema: './dev-test/gql-tag-operations/schema.graphql', documents: './dev-test/gql-tag-operations/src/**/*.ts', preset: 'gql-tag-operations-preset', - plugins: [], }, './dev-test/gql-tag-operations/graphql/': { schema: './dev-test/gql-tag-operations/schema.graphql', documents: './dev-test/gql-tag-operations/src/**/*.ts', preset: 'client', - plugins: [], }, './dev-test/gql-tag-operations-urql/gql': { schema: './dev-test/gql-tag-operations-urql/schema.graphql', documents: './dev-test/gql-tag-operations-urql/src/**/*.ts', preset: 'gql-tag-operations-preset', presetConfig: { augmentedModuleName: '@urql/core' }, - plugins: [], }, './dev-test/gql-tag-operations-masking/gql': { schema: './dev-test/gql-tag-operations-masking/schema.graphql', documents: './dev-test/gql-tag-operations-masking/src/**/*.tsx', preset: 'gql-tag-operations-preset', presetConfig: { fragmentMasking: true }, - plugins: [], }, './dev-test/gql-tag-operations-masking-star-wars/gql': { schema: './dev-test/gql-tag-operations-masking-star-wars/schema.json', documents: './dev-test/gql-tag-operations-masking-star-wars/src/**/*.tsx', preset: 'gql-tag-operations-preset', presetConfig: { fragmentMasking: true }, - plugins: [], }, }, }; diff --git a/examples/front-end/advanced/babel-optimized/codegen.ts b/examples/front-end/advanced/babel-optimized/codegen.ts index 1650c1f8ea3..779caaa08cc 100644 --- a/examples/front-end/advanced/babel-optimized/codegen.ts +++ b/examples/front-end/advanced/babel-optimized/codegen.ts @@ -6,7 +6,6 @@ const config: CodegenConfig = { generates: { './src/gql/': { preset: 'client', - plugins: [], }, }, }; diff --git a/examples/front-end/react/apollo-client/codegen.ts b/examples/front-end/react/apollo-client/codegen.ts index 1650c1f8ea3..779caaa08cc 100644 --- a/examples/front-end/react/apollo-client/codegen.ts +++ b/examples/front-end/react/apollo-client/codegen.ts @@ -6,7 +6,6 @@ const config: CodegenConfig = { generates: { './src/gql/': { preset: 'client', - plugins: [], }, }, }; diff --git a/examples/front-end/react/graphql-request/codegen.ts b/examples/front-end/react/graphql-request/codegen.ts index 1650c1f8ea3..779caaa08cc 100644 --- a/examples/front-end/react/graphql-request/codegen.ts +++ b/examples/front-end/react/graphql-request/codegen.ts @@ -6,7 +6,6 @@ const config: CodegenConfig = { generates: { './src/gql/': { preset: 'client', - plugins: [], }, }, }; diff --git a/examples/front-end/react/swr/codegen.ts b/examples/front-end/react/swr/codegen.ts index 86baf179af3..13c1d18fa9e 100644 --- a/examples/front-end/react/swr/codegen.ts +++ b/examples/front-end/react/swr/codegen.ts @@ -6,7 +6,6 @@ const config: CodegenConfig = { generates: { './gql/': { preset: 'client', - plugins: [], }, }, }; diff --git a/examples/front-end/react/tanstack-react-query/codegen.ts b/examples/front-end/react/tanstack-react-query/codegen.ts index 1650c1f8ea3..779caaa08cc 100644 --- a/examples/front-end/react/tanstack-react-query/codegen.ts +++ b/examples/front-end/react/tanstack-react-query/codegen.ts @@ -6,7 +6,6 @@ const config: CodegenConfig = { generates: { './src/gql/': { preset: 'client', - plugins: [], }, }, }; diff --git a/examples/front-end/react/urql/codegen.ts b/examples/front-end/react/urql/codegen.ts index 1650c1f8ea3..779caaa08cc 100644 --- a/examples/front-end/react/urql/codegen.ts +++ b/examples/front-end/react/urql/codegen.ts @@ -6,7 +6,6 @@ const config: CodegenConfig = { generates: { './src/gql/': { preset: 'client', - plugins: [], }, }, }; diff --git a/examples/front-end/vue/apollo-composable/codegen.ts b/examples/front-end/vue/apollo-composable/codegen.ts index 09c639cbdcf..0bc7193f78a 100644 --- a/examples/front-end/vue/apollo-composable/codegen.ts +++ b/examples/front-end/vue/apollo-composable/codegen.ts @@ -9,7 +9,6 @@ const config: CodegenConfig = { config: { useTypeImports: true, }, - plugins: [], }, }, }; diff --git a/examples/front-end/vue/urql/codegen.ts b/examples/front-end/vue/urql/codegen.ts index 09c639cbdcf..0bc7193f78a 100644 --- a/examples/front-end/vue/urql/codegen.ts +++ b/examples/front-end/vue/urql/codegen.ts @@ -9,7 +9,6 @@ const config: CodegenConfig = { config: { useTypeImports: true, }, - plugins: [], }, }, }; diff --git a/examples/front-end/vue/villus/codegen.ts b/examples/front-end/vue/villus/codegen.ts index 09c639cbdcf..0bc7193f78a 100644 --- a/examples/front-end/vue/villus/codegen.ts +++ b/examples/front-end/vue/villus/codegen.ts @@ -9,7 +9,6 @@ const config: CodegenConfig = { config: { useTypeImports: true, }, - plugins: [], }, }, }; diff --git a/examples/persisted-documents/codegen.ts b/examples/persisted-documents/codegen.ts index 5b2ae7bad31..39aae6f2c5f 100644 --- a/examples/persisted-documents/codegen.ts +++ b/examples/persisted-documents/codegen.ts @@ -6,7 +6,6 @@ const config: CodegenConfig = { documents: ['src/**/*.ts'], generates: { './src/gql/': { - plugins: [], preset: 'client-preset', presetConfig: { persistedDocuments: true, diff --git a/examples/typescript-esm/codegen.cjs b/examples/typescript-esm/codegen.cjs index dffbb02420a..47272833f71 100644 --- a/examples/typescript-esm/codegen.cjs +++ b/examples/typescript-esm/codegen.cjs @@ -7,7 +7,6 @@ const config = { emitLegacyCommonJSImports: false, generates: { './src/gql/': { - plugins: [], preset: 'client-preset', }, }, diff --git a/packages/graphql-codegen-cli/tests/codegen.spec.ts b/packages/graphql-codegen-cli/tests/codegen.spec.ts index 7c4c511d2ae..079bd23f1a5 100644 --- a/packages/graphql-codegen-cli/tests/codegen.spec.ts +++ b/packages/graphql-codegen-cli/tests/codegen.spec.ts @@ -164,23 +164,47 @@ describe('Codegen Executor', () => { } }); - it('Should throw when one output has no plugins defined', async () => { + it.only('Should throw when one output has no plugins or preset defined', async () => { + expect.assertions(1); try { await executeCodegen({ + schema: SIMPLE_TEST_SCHEMA, + generates: { + 'out.ts': {}, + }, + }); + } catch (e) { + expect(e.message).toMatch('Invalid Codegen Configuration!'); + } + }); + + it.only('Should throw when one output has no plugins defined', async () => { + expect.assertions(1); + try { + await executeCodegen({ + schema: SIMPLE_TEST_SCHEMA, generates: { 'out.ts': { plugins: [], }, }, }); - - throw new Error(SHOULD_NOT_THROW_STRING); } catch (e) { - expect(e.message).not.toBe(SHOULD_NOT_THROW_STRING); expect(e.message).toMatch('Invalid Codegen Configuration!'); } }); + it.only('Should succeed when one output has no plugins but preset defined', async () => { + await executeCodegen({ + schema: SIMPLE_TEST_SCHEMA, + generates: { + './src/gql/': { + preset: 'client-preset', + }, + }, + }); + }); + it('should handle extend keyword when GraphQLSchema is used', async () => { const output = await executeCodegen({ schema: './tests/test-files/schema-dir/with-extend.js', diff --git a/packages/presets/client/tests/client-preset.spec.ts b/packages/presets/client/tests/client-preset.spec.ts index 5d3f9a6012f..e801457d029 100644 --- a/packages/presets/client/tests/client-preset.spec.ts +++ b/packages/presets/client/tests/client-preset.spec.ts @@ -21,7 +21,6 @@ describe('client-preset', () => { generates: { 'out1/': { preset, - plugins: [], }, }, }); @@ -109,7 +108,6 @@ export * from "./gql";`); generates: { 'out1/': { preset, - plugins: [], }, }, }); @@ -197,7 +195,6 @@ export * from "./gql";`); generates: { 'out1/': { preset, - plugins: [], }, }, }); @@ -273,7 +270,6 @@ export * from "./gql";`); generates: { 'out1/': { preset, - plugins: [], }, }, config: { @@ -402,7 +398,6 @@ export * from "./gql";`); generates: { 'out1/': { preset, - plugins: [], }, }, config: { @@ -524,7 +519,6 @@ export * from "./gql";`); generates: { 'out1/': { preset, - plugins: [], }, }, config: { @@ -629,7 +623,6 @@ export * from "./gql";`); generates: { 'out1/': { preset, - plugins: [], presetConfig: { fragmentMasking: false, }, @@ -717,7 +710,6 @@ export * from "./gql";`); generates: { 'out1/': { preset, - plugins: [], presetConfig: { fragmentMasking: {}, }, @@ -743,7 +735,6 @@ export * from "./gql";`); generates: { 'out1/': { preset, - plugins: [], presetConfig: { fragmentMasking: { unmaskFunctionName: 'iLikeTurtles', @@ -859,7 +850,6 @@ export * from "./gql";`); generates: { 'out1/': { preset, - plugins: [], presetConfig: { fragmentMasking: true, }, @@ -899,7 +889,6 @@ export * from "./gql";`); generates: { 'out1/': { preset, - plugins: [], presetConfig: { fragmentMasking: true, }, @@ -937,7 +926,6 @@ export * from "./gql";`); generates: { 'out1/': { preset, - plugins: [], }, }, emitLegacyCommonJSImports: false, @@ -1026,7 +1014,6 @@ export * from "./gql.js";`); generates: { 'out1/': { preset, - plugins: [], }, }, emitLegacyCommonJSImports: false, @@ -1098,7 +1085,6 @@ export * from "./gql.js";`); generates: { 'out1/': { preset, - plugins: [], presetConfig: { onExecutableDocumentNode(node) { return { @@ -1167,7 +1153,6 @@ export * from "./gql.js";`); generates: { 'out1/': { preset, - plugins: [], presetConfig: { persistedDocuments: true, }, @@ -1245,7 +1230,6 @@ export * from "./gql.js";`); generates: { 'out1/': { preset, - plugins: [], presetConfig: { persistedDocuments: { mode: 'replaceDocumentWithHash', @@ -1325,7 +1309,6 @@ export * from "./gql.js";`); generates: { 'out1/': { preset, - plugins: [], presetConfig: { persistedDocuments: { hashPropertyName: 'custom_property_name', @@ -1416,7 +1399,6 @@ export * from "./gql.js";`); generates: { 'out1/': { preset, - plugins: [], presetConfig: { persistedDocuments: true, onExecutableDocumentNode(node) { diff --git a/packages/presets/gql-tag-operations/src/index.ts b/packages/presets/gql-tag-operations/src/index.ts index aba70beef8f..f6338fcf46b 100644 --- a/packages/presets/gql-tag-operations/src/index.ts +++ b/packages/presets/gql-tag-operations/src/index.ts @@ -36,7 +36,6 @@ export type GqlTagConfig = { * generates: { * 'path/to/file.ts': { * preset: 'gql-tag-operations', - * plugins: [], * presetConfig: { * augmentedModuleName: '@urql/core' * }, @@ -58,7 +57,6 @@ export type GqlTagConfig = { * generates: { * 'path/to/file.ts': { * preset: 'gql-tag-operations', - * plugins: [], * presetConfig: { * fragmentMasking: true * }, @@ -78,7 +76,6 @@ export type GqlTagConfig = { * generates: { * 'path/to/file.ts': { * preset: 'gql-tag-operations', - * plugins: [], * presetConfig: { * augmentedModuleName: '@urql/core', * fragmentMasking: { @@ -107,7 +104,6 @@ export type GqlTagConfig = { * generates: { * 'path/to/file.ts': { * preset: 'gql-tag-operations', - * plugins: [], * presetConfig: { * gqlTagName: 'graphql' * }, diff --git a/packages/presets/gql-tag-operations/tests/gql-tag-operations.spec.ts b/packages/presets/gql-tag-operations/tests/gql-tag-operations.spec.ts index 85c3c1ef31f..105648617c2 100644 --- a/packages/presets/gql-tag-operations/tests/gql-tag-operations.spec.ts +++ b/packages/presets/gql-tag-operations/tests/gql-tag-operations.spec.ts @@ -21,7 +21,6 @@ describe('gql-tag-operations-preset', () => { generates: { out1: { preset, - plugins: [], }, }, }); @@ -108,7 +107,6 @@ describe('gql-tag-operations-preset', () => { generates: { out1: { preset, - plugins: [], }, }, }); @@ -195,7 +193,6 @@ describe('gql-tag-operations-preset', () => { generates: { out1: { preset, - plugins: [], }, }, }); @@ -271,7 +268,6 @@ describe('gql-tag-operations-preset', () => { generates: { out1: { preset, - plugins: [], }, }, config: { @@ -398,7 +394,6 @@ describe('gql-tag-operations-preset', () => { generates: { out1: { preset, - plugins: [], }, }, config: { @@ -503,7 +498,6 @@ describe('gql-tag-operations-preset', () => { generates: { out1: { preset, - plugins: [], presetConfig: { fragmentMasking: true, }, @@ -584,7 +578,6 @@ describe('gql-tag-operations-preset', () => { generates: { out1: { preset, - plugins: [], presetConfig: { fragmentMasking: {}, }, @@ -610,7 +603,6 @@ describe('gql-tag-operations-preset', () => { generates: { out1: { preset, - plugins: [], presetConfig: { fragmentMasking: { unmaskFunctionName: 'iLikeTurtles', @@ -719,7 +711,6 @@ describe('gql-tag-operations-preset', () => { generates: { out1: { preset, - plugins: [], presetConfig: { fragmentMasking: true, }, @@ -759,7 +750,6 @@ describe('gql-tag-operations-preset', () => { generates: { out1: { preset, - plugins: [], presetConfig: { fragmentMasking: true, }, @@ -796,7 +786,6 @@ describe('gql-tag-operations-preset', () => { generates: { out1: { preset, - plugins: [], presetConfig: { fragmentMasking: { augmentedModuleName: '@urql/fragment', @@ -865,7 +854,6 @@ describe('gql-tag-operations-preset', () => { generates: { out1: { preset, - plugins: [], }, }, emitLegacyCommonJSImports: false, diff --git a/packages/utils/plugins-helpers/src/helpers.ts b/packages/utils/plugins-helpers/src/helpers.ts index 56ba5513ce8..2755a9cca1b 100644 --- a/packages/utils/plugins-helpers/src/helpers.ts +++ b/packages/utils/plugins-helpers/src/helpers.ts @@ -25,7 +25,7 @@ export function isOutputConfigArray(type: any): type is Types.OutputConfig[] { } export function isConfiguredOutput(type: any): type is Types.ConfiguredOutput { - return (typeof type === 'object' && type.plugins) || type.preset; + return typeof type === 'object'; } export function normalizeOutputParam( diff --git a/website/src/pages/docs/config-reference/codegen-config.mdx b/website/src/pages/docs/config-reference/codegen-config.mdx index 60c3bf82049..2972f1897de 100644 --- a/website/src/pages/docs/config-reference/codegen-config.mdx +++ b/website/src/pages/docs/config-reference/codegen-config.mdx @@ -24,8 +24,7 @@ const config: CodegenConfig = { documents: ['src/**/*.tsx'], generates: { './src/gql/': { - preset: 'client', - plugins: [] + preset: 'client' } } } @@ -107,8 +106,7 @@ const config: CodegenConfig = { documents: ['src/**/*.tsx'], generates: { './src/gql/': { - preset: 'client', - plugins: [] + preset: 'client' } } } diff --git a/website/src/pages/docs/config-reference/lifecycle-hooks.mdx b/website/src/pages/docs/config-reference/lifecycle-hooks.mdx index ce0f8d3c87b..9629f22b7ce 100644 --- a/website/src/pages/docs/config-reference/lifecycle-hooks.mdx +++ b/website/src/pages/docs/config-reference/lifecycle-hooks.mdx @@ -20,8 +20,7 @@ const config: CodegenConfig = { documents: ['src/**/*.tsx'], generates: { './src/gql/': { - preset: 'client', - plugins: [] + preset: 'client' } }, hooks: { @@ -43,7 +42,6 @@ const config: CodegenConfig = { generates: { './src/gql/': { preset: 'client', - plugins: [], hooks: { afterOneFileWrite: ['prettier --write'] } diff --git a/website/src/pages/docs/getting-started/esm-typescript-usage.mdx b/website/src/pages/docs/getting-started/esm-typescript-usage.mdx index a0a2cd09b28..61d71417b94 100644 --- a/website/src/pages/docs/getting-started/esm-typescript-usage.mdx +++ b/website/src/pages/docs/getting-started/esm-typescript-usage.mdx @@ -33,8 +33,7 @@ const config: CodegenConfig = { emitLegacyCommonJSImports: false, generates: { './src/gql/': { - preset: 'client', - plugins: [] + preset: 'client' } } } diff --git a/website/src/pages/docs/getting-started/index.mdx b/website/src/pages/docs/getting-started/index.mdx index 9a2706be0ea..13752691e52 100644 --- a/website/src/pages/docs/getting-started/index.mdx +++ b/website/src/pages/docs/getting-started/index.mdx @@ -270,7 +270,6 @@ const config: CodegenConfig = { generates: { './src/gql/': { preset: 'client', - plugins: [] } } } diff --git a/website/src/pages/docs/guides/api-testing.mdx b/website/src/pages/docs/guides/api-testing.mdx index ac20316829b..fca30b5f0cc 100644 --- a/website/src/pages/docs/guides/api-testing.mdx +++ b/website/src/pages/docs/guides/api-testing.mdx @@ -69,7 +69,6 @@ const config: CodegenConfig = { documents: ['src/**/*.ts'], generates: { './src/gql/': { - plugins: [], preset: 'client-preset' } } diff --git a/website/src/pages/docs/guides/graphql-server-apollo-yoga-with-server-preset.mdx b/website/src/pages/docs/guides/graphql-server-apollo-yoga-with-server-preset.mdx index a0cfff8b142..dbeff3eee99 100644 --- a/website/src/pages/docs/guides/graphql-server-apollo-yoga-with-server-preset.mdx +++ b/website/src/pages/docs/guides/graphql-server-apollo-yoga-with-server-preset.mdx @@ -73,8 +73,7 @@ const config: CodegenConfig = { schema: '**/schema.graphql', generates: { 'src/schema': { - preset, - plugins: [] + preset } } } diff --git a/website/src/pages/docs/guides/react-vue.mdx b/website/src/pages/docs/guides/react-vue.mdx index 815451e1b95..addf0c90823 100644 --- a/website/src/pages/docs/guides/react-vue.mdx +++ b/website/src/pages/docs/guides/react-vue.mdx @@ -81,8 +81,7 @@ const config: CodegenConfig = { ignoreNoDocuments: true, // for better experience with the watcher generates: { './src/gql/': { - preset: 'client', - plugins: [] + preset: 'client' } } } @@ -106,8 +105,7 @@ const config: CodegenConfig = { preset: 'client', config: { useTypeImports: true - }, - plugins: [] + } } } } diff --git a/website/src/pages/plugins/presets/gql-tag-operations-preset.mdx b/website/src/pages/plugins/presets/gql-tag-operations-preset.mdx index 9e58fcef0d0..596591a4ee4 100644 --- a/website/src/pages/plugins/presets/gql-tag-operations-preset.mdx +++ b/website/src/pages/plugins/presets/gql-tag-operations-preset.mdx @@ -46,8 +46,7 @@ const config: CodegenConfig = { documents: ['src/**/*.ts', '!src/gql/**/*'], generates: { './src/gql/': { - preset: 'gql-tag-operations-preset', - plugins: [] + preset: 'gql-tag-operations-preset' } } } @@ -238,7 +237,6 @@ const config: CodegenConfig = { generates: { 'src/gql/': { preset: 'gql-tag-operations-preset', - plugins: [], presetConfig: { augmentedModuleName: '@urql/core' } @@ -313,7 +311,6 @@ const config: CodegenConfig = { generates: { 'src/gql/': { preset: 'gql-tag-operations-preset', - plugins: [], presetConfig: { fragmentMasking: true } @@ -392,7 +389,6 @@ const config: CodegenConfig = { generates: { 'src/gql/': { preset: 'gql-tag-operations-preset', - plugins: [], presetConfig: { fragmentMasking: { unmaskFunctionName: 'getFragment' @@ -417,7 +413,6 @@ const config: CodegenConfig = { generates: { 'src/gql/': { preset: 'gql-tag-operations-preset', - plugins: [], presetConfig: { fragmentMasking: { augmentedModuleName: '@something/fragment' diff --git a/website/src/pages/plugins/presets/preset-client.mdx b/website/src/pages/plugins/presets/preset-client.mdx index 1d62fccc938..6ce0014de3e 100644 --- a/website/src/pages/plugins/presets/preset-client.mdx +++ b/website/src/pages/plugins/presets/preset-client.mdx @@ -183,7 +183,6 @@ const config: CodegenConfig = { generates: { './src/gql/': { preset: 'client', - plugins: [], presetConfig: { fragmentMasking: { unmaskFunctionName: 'getFragmentData' } } @@ -293,7 +292,6 @@ const config: CodegenConfig = { generates: { './src/gql/': { preset: 'client', - plugins: [], presetConfig: { fragmentMasking: false } @@ -325,7 +323,6 @@ const config: CodegenConfig = { generates: { './src/gql/': { preset: 'client', - plugins: [], presetConfig: { persistedDocuments: true }