dotansimha / dotansimha/graphql-code-generator
Unable to load preset matching client
- 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
I try to generate typings using `@graphql-codegen/cli` (programmatically, using `generate` function) with `client` preset error happens:
`Unable to load preset matching client`
```
✔ Parse Configuration
⚠ Generate outputs
✖ Unable to load preset matching client
Unable to load preset matching 'client'.
Reason:
Cannot find package '@graphql-codegen/client' imported from /project-path/node_modules/@graphql-codegen/cli/esm/codegen.js
```
If you change `preset` from `client` to `client-preset` — everything works fine
### Your Example Website or App
—
### Steps to Reproduce the Bug or Issue
1. install `@graphql-codegen/cli` and `@graphql-codegen/client-preset` both with versions `4.0.1`
2. set value of preset field in object under generates field to `client`:
```
generates: {
'src/__generated__/graphql/': {
schema: join(projectPath, 'config/graphql/schema.graphql'),
documents: [`${projectPath}/src/**/*.{ts,tsx}`],
preset: 'client', // set `client` here
plugins: [],
config: {
strictScalars: true,
defaultScalarType: 'unknown',
scalars: {
Date: 'string',
DateTime: 'string',
Decimal: 'number',
UUID: 'string',
},
},
},
},
```
3. try to generate types programmatically using `generate` function from `@graphql-codegen/cli` package
4. error `Unable to load preset matching client` should happen
### Expected behavior
Error should not happen if you change preset field from `client-preset` to `client`
### Screenshots or Videos
_No response_
### Platform
- OS: macOS
- NodeJS: 16.13.2
- `graphql` version: 16.7.1
- `@graphql-codegen/*` version(s): 4.0.1
### Codegen Config File
```ts
import { join } from 'node:path';
import { CodegenConfig } from '@graphql-codegen/cli';
export const getGraphQLCodegenConfig = (projectPath: string, watch: boolean): CodegenConfig => ({
watch,
ignoreNoDocuments: true,
hooks: {
afterOneFileWrite: ['eslint --fix'],
},
generates: {
'src/__generated__/graphql/rbf/': {
schema: join(projectPath, 'config/graphql/schemas/rbf-sales-portal.graphql'),
documents: [`${projectPath}/src/**/*.rbf.{ts,tsx}`],
preset: 'client',
plugins: [],
config: {
strictScalars: true,
defaultScalarType: 'unknown',
scalars: {
Date: 'string',
DateTime: 'string',
Decimal: 'number',
UUID: 'string',
},
},
},
},
});
```
### Additional context
_No response_
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.