Skip to content

Commit

Permalink
fix: make plugins optional for preset (#6305)
Browse files Browse the repository at this point in the history
  • Loading branch information
n1ru4l committed Jul 13, 2021
1 parent 6fa7e30 commit 470336a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changeset/loud-toys-draw.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@graphql-codegen/cli': patch
'@graphql-codegen/plugin-helpers': patch
---

don't require plugins for for config if preset provides plugin. Instead the preset should throw if no plugins were provided.
4 changes: 2 additions & 2 deletions packages/graphql-codegen-cli/src/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ export async function executeCodegen(input: CodegenContext | Types.Config): Prom
}

for (const filename of generateKeys) {
generates[filename] = normalizeOutputParam(config.generates[filename]);
const output = (generates[filename] = normalizeOutputParam(config.generates[filename]));

if (generates[filename].plugins.length === 0) {
if (!output.preset && (!output.plugins || output.plugins.length === 0)) {
throw new DetailedError(
'Invalid Codegen Configuration!',
`
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/plugins-helpers/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
return (typeof type === 'object' && type.plugins) || type.preset;
}

export function normalizeOutputParam(config: Types.OutputConfig | Types.ConfiguredOutput): Types.ConfiguredOutput {
Expand Down

0 comments on commit 470336a

Please sign in to comment.