dotansimha / dotansimha/graphql-code-generator

CLI exits with code 1 without an error message if directory is listed as output instead of file

Open
#9,272 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
TypeScript
Stars
11.3k
Forks
1.4k
Avg merge
1d 1h
Merged PRs (30d)
23

Description

### Which packages are impacted by your issue?

@graphql-codegen/cli

### Describe the bug

If you accidentally specify a directory instead of a filepath as a key in `generates`, the `graphql-codegen` command will exit with an error code of 1, but provide no other messaging as to what's gone wrong.

### Your Example Website or App

https://stackblitz.com/edit/github-itj2kj?file=package.json

### Steps to Reproduce the Bug or Issue

In the StackBlitz example terminal, run: `npm run codegen && echo done`

Notice that "done" is not printed; this is because the `codegen` step exits with code 1.

If you change `output` to `"output/types.ts"` in the `codegen.ts` file and run the same command, you'll see that the operation completes and prints out "done".

### Expected behavior

As a user, I expected some sort of error message to indicate what I've done wrong here, but instead an exit code (and a lack of generated output) is my only indication that anything's gone wrong at all.

### Screenshots or Videos

_No response_

### Platform

- OS: macOS 12.6.3
- NodeJS: v14.21.3 (but StackBlitz is on v16.14.2)
- `graphql` version: v16.6.0
- `@graphql-codegen/*` version(s):
- @graphql-codegen/cli@3.3.0
- @graphql-codegen/core@3.1.0
- @graphql-codegen/introspection@3.0.1
- @graphql-codegen/plugin-helpers@4.2.0
- @graphql-codegen/schema-ast@3.0.1
- @graphql-codegen/typescript-operations@3.0.3
- @graphql-codegen/typescript-resolvers@3.2.0
- @graphql-codegen/typescript@3.0.3
- @graphql-codegen/visitor-plugin-common@3.1.0

### Codegen Config File

```
import { CodegenConfig } from '@graphql-codegen/cli';

const config: CodegenConfig = {
schema: 'schema.graphql',
documents: 'document.graphql',
generates: {
// "output" is a directory
output: { plugins: ['typescript', 'typescript-operations'] },
},
};

export default config;
```

### Additional context

From stepping through the CLI code, it looks like there's just no error reporting on the output step.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.