Skip to content

Commit

Permalink
feat: mark plugins as optional (#8893)
Browse files Browse the repository at this point in the history
  • Loading branch information
n1ru4l authored Feb 15, 2023
1 parent 6fa3f0a commit a118c30
Show file tree
Hide file tree
Showing 31 changed files with 50 additions and 84 deletions.
7 changes: 7 additions & 0 deletions .changeset/bright-islands-pretend.md
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions .changeset/chilly-beers-sleep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-codegen/plugin-helpers': minor
---

mark `plugins` in config optional
5 changes: 0 additions & 5 deletions dev-test/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
},
},
};
Expand Down
1 change: 0 additions & 1 deletion examples/persisted-documents/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const config: CodegenConfig = {
documents: ['src/**/*.ts'],
generates: {
'./src/gql/': {
plugins: [],
preset: 'client-preset',
presetConfig: {
persistedDocuments: true,
Expand Down
1 change: 0 additions & 1 deletion examples/react/apollo-client/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const config: CodegenConfig = {
generates: {
'./src/gql/': {
preset: 'client',
plugins: [],
},
},
hooks: { afterAllFileWrite: ['prettier --write'] },
Expand Down
1 change: 0 additions & 1 deletion examples/react/babel-optimized/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const config: CodegenConfig = {
generates: {
'./src/gql/': {
preset: 'client',
plugins: [],
},
},
hooks: { afterAllFileWrite: ['prettier --write'] },
Expand Down
1 change: 0 additions & 1 deletion examples/react/graphql-request/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const config: CodegenConfig = {
generates: {
'./src/gql/': {
preset: 'client',
plugins: [],
},
},
hooks: { afterAllFileWrite: ['prettier --write'] },
Expand Down
1 change: 0 additions & 1 deletion examples/react/nextjs-swr/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const config: CodegenConfig = {
generates: {
'./gql/': {
preset: 'client',
plugins: [],
},
},
hooks: { afterAllFileWrite: ['prettier --write'] },
Expand Down
1 change: 0 additions & 1 deletion examples/react/tanstack-react-query/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const config: CodegenConfig = {
generates: {
'./src/gql/': {
preset: 'client',
plugins: [],
},
},
hooks: { afterAllFileWrite: ['prettier --write'] },
Expand Down
1 change: 0 additions & 1 deletion examples/react/urql/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const config: CodegenConfig = {
generates: {
'./src/gql/': {
preset: 'client',
plugins: [],
},
},
hooks: { afterAllFileWrite: ['prettier --write'] },
Expand Down
1 change: 0 additions & 1 deletion examples/typescript-esm/codegen.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const config = {
emitLegacyCommonJSImports: false,
generates: {
'./src/gql/': {
plugins: [],
preset: 'client-preset',
},
},
Expand Down
1 change: 0 additions & 1 deletion examples/typescript-graphql-request/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const config: CodegenConfig = {
generates: {
'./src/gql/': {
preset: 'client',
plugins: [],
},
},
hooks: { afterAllFileWrite: ['prettier --write'] },
Expand Down
1 change: 0 additions & 1 deletion examples/vue/apollo-composable/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const config: CodegenConfig = {
config: {
useTypeImports: true,
},
plugins: [],
},
},
hooks: { afterAllFileWrite: ['prettier --write'] },
Expand Down
1 change: 0 additions & 1 deletion examples/vue/urql/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const config: CodegenConfig = {
config: {
useTypeImports: true,
},
plugins: [],
},
},
hooks: { afterAllFileWrite: ['prettier --write'] },
Expand Down
1 change: 0 additions & 1 deletion examples/vue/villus/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const config: CodegenConfig = {
config: {
useTypeImports: true,
},
plugins: [],
},
},
hooks: { afterAllFileWrite: ['prettier --write'] },
Expand Down
1 change: 0 additions & 1 deletion examples/yoga-tests/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const config: CodegenConfig = {
documents: ['src/**/*.ts'],
generates: {
'./src/gql/': {
plugins: [],
preset: 'client-preset',
},
},
Expand Down
32 changes: 28 additions & 4 deletions packages/graphql-codegen-cli/tests/codegen.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
18 changes: 0 additions & 18 deletions packages/presets/client/tests/client-preset.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ describe('client-preset', () => {
generates: {
'out1/': {
preset,
plugins: [],
},
},
});
Expand Down Expand Up @@ -109,7 +108,6 @@ export * from "./gql";`);
generates: {
'out1/': {
preset,
plugins: [],
},
},
});
Expand Down Expand Up @@ -197,7 +195,6 @@ export * from "./gql";`);
generates: {
'out1/': {
preset,
plugins: [],
},
},
});
Expand Down Expand Up @@ -273,7 +270,6 @@ export * from "./gql";`);
generates: {
'out1/': {
preset,
plugins: [],
},
},
config: {
Expand Down Expand Up @@ -402,7 +398,6 @@ export * from "./gql";`);
generates: {
'out1/': {
preset,
plugins: [],
},
},
config: {
Expand Down Expand Up @@ -524,7 +519,6 @@ export * from "./gql";`);
generates: {
'out1/': {
preset,
plugins: [],
},
},
config: {
Expand Down Expand Up @@ -629,7 +623,6 @@ export * from "./gql";`);
generates: {
'out1/': {
preset,
plugins: [],
presetConfig: {
fragmentMasking: false,
},
Expand Down Expand Up @@ -717,7 +710,6 @@ export * from "./gql";`);
generates: {
'out1/': {
preset,
plugins: [],
presetConfig: {
fragmentMasking: {},
},
Expand All @@ -743,7 +735,6 @@ export * from "./gql";`);
generates: {
'out1/': {
preset,
plugins: [],
presetConfig: {
fragmentMasking: {
unmaskFunctionName: 'iLikeTurtles',
Expand Down Expand Up @@ -859,7 +850,6 @@ export * from "./gql";`);
generates: {
'out1/': {
preset,
plugins: [],
presetConfig: {
fragmentMasking: true,
},
Expand Down Expand Up @@ -899,7 +889,6 @@ export * from "./gql";`);
generates: {
'out1/': {
preset,
plugins: [],
presetConfig: {
fragmentMasking: true,
},
Expand Down Expand Up @@ -937,7 +926,6 @@ export * from "./gql";`);
generates: {
'out1/': {
preset,
plugins: [],
},
},
emitLegacyCommonJSImports: false,
Expand Down Expand Up @@ -1026,7 +1014,6 @@ export * from "./gql.js";`);
generates: {
'out1/': {
preset,
plugins: [],
},
},
emitLegacyCommonJSImports: false,
Expand Down Expand Up @@ -1098,7 +1085,6 @@ export * from "./gql.js";`);
generates: {
'out1/': {
preset,
plugins: [],
presetConfig: {
onExecutableDocumentNode(node) {
return {
Expand Down Expand Up @@ -1167,7 +1153,6 @@ export * from "./gql.js";`);
generates: {
'out1/': {
preset,
plugins: [],
presetConfig: {
persistedDocuments: true,
},
Expand Down Expand Up @@ -1245,7 +1230,6 @@ export * from "./gql.js";`);
generates: {
'out1/': {
preset,
plugins: [],
presetConfig: {
persistedDocuments: {
mode: 'replaceDocumentWithHash',
Expand Down Expand Up @@ -1325,7 +1309,6 @@ export * from "./gql.js";`);
generates: {
'out1/': {
preset,
plugins: [],
presetConfig: {
persistedDocuments: {
hashPropertyName: 'custom_property_name',
Expand Down Expand Up @@ -1416,7 +1399,6 @@ export * from "./gql.js";`);
generates: {
'out1/': {
preset,
plugins: [],
presetConfig: {
persistedDocuments: true,
onExecutableDocumentNode(node) {
Expand Down
4 changes: 0 additions & 4 deletions packages/presets/gql-tag-operations/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export type GqlTagConfig = {
* generates: {
* 'path/to/file.ts': {
* preset: 'gql-tag-operations',
* plugins: [],
* presetConfig: {
* augmentedModuleName: '@urql/core'
* },
Expand All @@ -58,7 +57,6 @@ export type GqlTagConfig = {
* generates: {
* 'path/to/file.ts': {
* preset: 'gql-tag-operations',
* plugins: [],
* presetConfig: {
* fragmentMasking: true
* },
Expand All @@ -78,7 +76,6 @@ export type GqlTagConfig = {
* generates: {
* 'path/to/file.ts': {
* preset: 'gql-tag-operations',
* plugins: [],
* presetConfig: {
* augmentedModuleName: '@urql/core',
* fragmentMasking: {
Expand Down Expand Up @@ -107,7 +104,6 @@ export type GqlTagConfig = {
* generates: {
* 'path/to/file.ts': {
* preset: 'gql-tag-operations',
* plugins: [],
* presetConfig: {
* gqlTagName: 'graphql'
* },
Expand Down
Loading

0 comments on commit a118c30

Please sign in to comment.