Skip to content

Commit a118c30

Browse files
authored
feat: mark plugins as optional (#8893)
1 parent 6fa3f0a commit a118c30

File tree

31 files changed

+50
-84
lines changed

31 files changed

+50
-84
lines changed

.changeset/bright-islands-pretend.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@graphql-codegen/cli': minor
3+
'@graphql-codegen/client-preset': minor
4+
'@graphql-codegen/gql-tag-operations-preset': minor
5+
---
6+
7+
It is no longer mandatory to declare an empty plugins array when using a preset

.changeset/chilly-beers-sleep.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-codegen/plugin-helpers': minor
3+
---
4+
5+
mark `plugins` in config optional

dev-test/codegen.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,34 +189,29 @@ const config: CodegenConfig = {
189189
schema: './dev-test/gql-tag-operations/schema.graphql',
190190
documents: './dev-test/gql-tag-operations/src/**/*.ts',
191191
preset: 'gql-tag-operations-preset',
192-
plugins: [],
193192
},
194193
'./dev-test/gql-tag-operations/graphql/': {
195194
schema: './dev-test/gql-tag-operations/schema.graphql',
196195
documents: './dev-test/gql-tag-operations/src/**/*.ts',
197196
preset: 'client',
198-
plugins: [],
199197
},
200198
'./dev-test/gql-tag-operations-urql/gql': {
201199
schema: './dev-test/gql-tag-operations-urql/schema.graphql',
202200
documents: './dev-test/gql-tag-operations-urql/src/**/*.ts',
203201
preset: 'gql-tag-operations-preset',
204202
presetConfig: { augmentedModuleName: '@urql/core' },
205-
plugins: [],
206203
},
207204
'./dev-test/gql-tag-operations-masking/gql': {
208205
schema: './dev-test/gql-tag-operations-masking/schema.graphql',
209206
documents: './dev-test/gql-tag-operations-masking/src/**/*.tsx',
210207
preset: 'gql-tag-operations-preset',
211208
presetConfig: { fragmentMasking: true },
212-
plugins: [],
213209
},
214210
'./dev-test/gql-tag-operations-masking-star-wars/gql': {
215211
schema: './dev-test/gql-tag-operations-masking-star-wars/schema.json',
216212
documents: './dev-test/gql-tag-operations-masking-star-wars/src/**/*.tsx',
217213
preset: 'gql-tag-operations-preset',
218214
presetConfig: { fragmentMasking: true },
219-
plugins: [],
220215
},
221216
},
222217
};

examples/persisted-documents/codegen.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const config: CodegenConfig = {
66
documents: ['src/**/*.ts'],
77
generates: {
88
'./src/gql/': {
9-
plugins: [],
109
preset: 'client-preset',
1110
presetConfig: {
1211
persistedDocuments: true,

examples/react/apollo-client/codegen.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ const config: CodegenConfig = {
77
generates: {
88
'./src/gql/': {
99
preset: 'client',
10-
plugins: [],
1110
},
1211
},
1312
hooks: { afterAllFileWrite: ['prettier --write'] },

examples/react/babel-optimized/codegen.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ const config: CodegenConfig = {
77
generates: {
88
'./src/gql/': {
99
preset: 'client',
10-
plugins: [],
1110
},
1211
},
1312
hooks: { afterAllFileWrite: ['prettier --write'] },

examples/react/graphql-request/codegen.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ const config: CodegenConfig = {
77
generates: {
88
'./src/gql/': {
99
preset: 'client',
10-
plugins: [],
1110
},
1211
},
1312
hooks: { afterAllFileWrite: ['prettier --write'] },

examples/react/nextjs-swr/codegen.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ const config: CodegenConfig = {
77
generates: {
88
'./gql/': {
99
preset: 'client',
10-
plugins: [],
1110
},
1211
},
1312
hooks: { afterAllFileWrite: ['prettier --write'] },

examples/react/tanstack-react-query/codegen.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ const config: CodegenConfig = {
77
generates: {
88
'./src/gql/': {
99
preset: 'client',
10-
plugins: [],
1110
},
1211
},
1312
hooks: { afterAllFileWrite: ['prettier --write'] },

examples/react/urql/codegen.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ const config: CodegenConfig = {
77
generates: {
88
'./src/gql/': {
99
preset: 'client',
10-
plugins: [],
1110
},
1211
},
1312
hooks: { afterAllFileWrite: ['prettier --write'] },

examples/typescript-esm/codegen.cjs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ const config = {
77
emitLegacyCommonJSImports: false,
88
generates: {
99
'./src/gql/': {
10-
plugins: [],
1110
preset: 'client-preset',
1211
},
1312
},

examples/typescript-graphql-request/codegen.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ const config: CodegenConfig = {
77
generates: {
88
'./src/gql/': {
99
preset: 'client',
10-
plugins: [],
1110
},
1211
},
1312
hooks: { afterAllFileWrite: ['prettier --write'] },

examples/vue/apollo-composable/codegen.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ const config: CodegenConfig = {
99
config: {
1010
useTypeImports: true,
1111
},
12-
plugins: [],
1312
},
1413
},
1514
hooks: { afterAllFileWrite: ['prettier --write'] },

examples/vue/urql/codegen.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ const config: CodegenConfig = {
99
config: {
1010
useTypeImports: true,
1111
},
12-
plugins: [],
1312
},
1413
},
1514
hooks: { afterAllFileWrite: ['prettier --write'] },

examples/vue/villus/codegen.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ const config: CodegenConfig = {
99
config: {
1010
useTypeImports: true,
1111
},
12-
plugins: [],
1312
},
1413
},
1514
hooks: { afterAllFileWrite: ['prettier --write'] },

examples/yoga-tests/codegen.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const config: CodegenConfig = {
66
documents: ['src/**/*.ts'],
77
generates: {
88
'./src/gql/': {
9-
plugins: [],
109
preset: 'client-preset',
1110
},
1211
},

packages/graphql-codegen-cli/tests/codegen.spec.ts

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,23 +164,47 @@ describe('Codegen Executor', () => {
164164
}
165165
});
166166

167-
it('Should throw when one output has no plugins defined', async () => {
167+
it.only('Should throw when one output has no plugins or preset defined', async () => {
168+
expect.assertions(1);
168169
try {
169170
await executeCodegen({
171+
schema: SIMPLE_TEST_SCHEMA,
172+
generates: {
173+
'out.ts': {},
174+
},
175+
});
176+
} catch (e) {
177+
expect(e.message).toMatch('Invalid Codegen Configuration!');
178+
}
179+
});
180+
181+
it.only('Should throw when one output has no plugins defined', async () => {
182+
expect.assertions(1);
183+
try {
184+
await executeCodegen({
185+
schema: SIMPLE_TEST_SCHEMA,
170186
generates: {
171187
'out.ts': {
172188
plugins: [],
173189
},
174190
},
175191
});
176-
177-
throw new Error(SHOULD_NOT_THROW_STRING);
178192
} catch (e) {
179-
expect(e.message).not.toBe(SHOULD_NOT_THROW_STRING);
180193
expect(e.message).toMatch('Invalid Codegen Configuration!');
181194
}
182195
});
183196

197+
it.only('Should succeed when one output has no plugins but preset defined', async () => {
198+
await executeCodegen({
199+
schema: SIMPLE_TEST_SCHEMA,
200+
generates: {
201+
'./src/gql/': {
202+
preset: 'client-preset',
203+
},
204+
},
205+
});
206+
});
207+
184208
it('should handle extend keyword when GraphQLSchema is used', async () => {
185209
const output = await executeCodegen({
186210
schema: './tests/test-files/schema-dir/with-extend.js',

packages/presets/client/tests/client-preset.spec.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ describe('client-preset', () => {
2121
generates: {
2222
'out1/': {
2323
preset,
24-
plugins: [],
2524
},
2625
},
2726
});
@@ -109,7 +108,6 @@ export * from "./gql";`);
109108
generates: {
110109
'out1/': {
111110
preset,
112-
plugins: [],
113111
},
114112
},
115113
});
@@ -197,7 +195,6 @@ export * from "./gql";`);
197195
generates: {
198196
'out1/': {
199197
preset,
200-
plugins: [],
201198
},
202199
},
203200
});
@@ -273,7 +270,6 @@ export * from "./gql";`);
273270
generates: {
274271
'out1/': {
275272
preset,
276-
plugins: [],
277273
},
278274
},
279275
config: {
@@ -402,7 +398,6 @@ export * from "./gql";`);
402398
generates: {
403399
'out1/': {
404400
preset,
405-
plugins: [],
406401
},
407402
},
408403
config: {
@@ -524,7 +519,6 @@ export * from "./gql";`);
524519
generates: {
525520
'out1/': {
526521
preset,
527-
plugins: [],
528522
},
529523
},
530524
config: {
@@ -629,7 +623,6 @@ export * from "./gql";`);
629623
generates: {
630624
'out1/': {
631625
preset,
632-
plugins: [],
633626
presetConfig: {
634627
fragmentMasking: false,
635628
},
@@ -717,7 +710,6 @@ export * from "./gql";`);
717710
generates: {
718711
'out1/': {
719712
preset,
720-
plugins: [],
721713
presetConfig: {
722714
fragmentMasking: {},
723715
},
@@ -743,7 +735,6 @@ export * from "./gql";`);
743735
generates: {
744736
'out1/': {
745737
preset,
746-
plugins: [],
747738
presetConfig: {
748739
fragmentMasking: {
749740
unmaskFunctionName: 'iLikeTurtles',
@@ -859,7 +850,6 @@ export * from "./gql";`);
859850
generates: {
860851
'out1/': {
861852
preset,
862-
plugins: [],
863853
presetConfig: {
864854
fragmentMasking: true,
865855
},
@@ -899,7 +889,6 @@ export * from "./gql";`);
899889
generates: {
900890
'out1/': {
901891
preset,
902-
plugins: [],
903892
presetConfig: {
904893
fragmentMasking: true,
905894
},
@@ -937,7 +926,6 @@ export * from "./gql";`);
937926
generates: {
938927
'out1/': {
939928
preset,
940-
plugins: [],
941929
},
942930
},
943931
emitLegacyCommonJSImports: false,
@@ -1026,7 +1014,6 @@ export * from "./gql.js";`);
10261014
generates: {
10271015
'out1/': {
10281016
preset,
1029-
plugins: [],
10301017
},
10311018
},
10321019
emitLegacyCommonJSImports: false,
@@ -1098,7 +1085,6 @@ export * from "./gql.js";`);
10981085
generates: {
10991086
'out1/': {
11001087
preset,
1101-
plugins: [],
11021088
presetConfig: {
11031089
onExecutableDocumentNode(node) {
11041090
return {
@@ -1167,7 +1153,6 @@ export * from "./gql.js";`);
11671153
generates: {
11681154
'out1/': {
11691155
preset,
1170-
plugins: [],
11711156
presetConfig: {
11721157
persistedDocuments: true,
11731158
},
@@ -1245,7 +1230,6 @@ export * from "./gql.js";`);
12451230
generates: {
12461231
'out1/': {
12471232
preset,
1248-
plugins: [],
12491233
presetConfig: {
12501234
persistedDocuments: {
12511235
mode: 'replaceDocumentWithHash',
@@ -1325,7 +1309,6 @@ export * from "./gql.js";`);
13251309
generates: {
13261310
'out1/': {
13271311
preset,
1328-
plugins: [],
13291312
presetConfig: {
13301313
persistedDocuments: {
13311314
hashPropertyName: 'custom_property_name',
@@ -1416,7 +1399,6 @@ export * from "./gql.js";`);
14161399
generates: {
14171400
'out1/': {
14181401
preset,
1419-
plugins: [],
14201402
presetConfig: {
14211403
persistedDocuments: true,
14221404
onExecutableDocumentNode(node) {

packages/presets/gql-tag-operations/src/index.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ export type GqlTagConfig = {
3636
* generates: {
3737
* 'path/to/file.ts': {
3838
* preset: 'gql-tag-operations',
39-
* plugins: [],
4039
* presetConfig: {
4140
* augmentedModuleName: '@urql/core'
4241
* },
@@ -58,7 +57,6 @@ export type GqlTagConfig = {
5857
* generates: {
5958
* 'path/to/file.ts': {
6059
* preset: 'gql-tag-operations',
61-
* plugins: [],
6260
* presetConfig: {
6361
* fragmentMasking: true
6462
* },
@@ -78,7 +76,6 @@ export type GqlTagConfig = {
7876
* generates: {
7977
* 'path/to/file.ts': {
8078
* preset: 'gql-tag-operations',
81-
* plugins: [],
8279
* presetConfig: {
8380
* augmentedModuleName: '@urql/core',
8481
* fragmentMasking: {
@@ -107,7 +104,6 @@ export type GqlTagConfig = {
107104
* generates: {
108105
* 'path/to/file.ts': {
109106
* preset: 'gql-tag-operations',
110-
* plugins: [],
111107
* presetConfig: {
112108
* gqlTagName: 'graphql'
113109
* },

0 commit comments

Comments
 (0)