dotansimha / dotansimha/graphql-code-generator

Setting generate folder to root of "documents" glob leads to error

Open
#9,200 0 comments 6 reactions 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
@graphql-codegen/client-preset

### Describe the bug

I have used the following config file trying to generate the types for my operations:

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

const config: CodegenConfig = {
overwrite: true,
schema: 'http://localhost:8080/api/graph',
documents: 'src/graphql/**/*.gql',
generates: {
'./src/graphql/': {
preset: 'client',
plugins: [],
config: {
useTypeImports: true
}
}
}
}

export default config
```

Executing `graphql-codegen --config codegen.ts` leads to the following output:

```
$ graphql-codegen --config codegen.ts
✔ Parse Configuration
⚠ Generate outputs
❯ Generate to ./src/graphql/
✔ Load GraphQL schemas

Unable to find any GraphQL type definitions for the following pointers:

- src/graphql/**/*.gql
◼ Generate
error Command failed with exit code 1.
```

Changing the following line (in the generates block):
'./src/graphql/'
to:
'./src/graphql/generated/'

let the process finish successfuly. The error message above is quite misleading and unclear for that case.

### Your Example Website or App

https://stackblitz.com/edit/github-aqhzsv?file=codegen.ts

### Steps to Reproduce the Bug or Issue

1. Set the output path of the generator to the root of the documents glob
2. Execute `graphql-codegen --config codegen.ts`
3. Leads to unclear/misleading error message

### Expected behavior

Either not fail at all or show a more helpful error message

### Platform

- OS: Windows
- NodeJS: 16.18.1
- `graphql` version: 16.6.0
- `@graphql-codegen/cli` version: 3.2.2
- `@graphql-codegen/client-preset` version: 2.1.1

### Codegen Config File

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

const config: CodegenConfig = {
overwrite: true,
schema: 'http://localhost:8080/api/graph',
documents: 'src/graphql/**/*.gql',
generates: {
'./src/graphql/': {
preset: 'client',
plugins: [],
config: {
useTypeImports: true
}
}
}
}

export default config
```

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.