Skip to content

Commit d19573d

Browse files
authored
feat(preset/client): allow the use of essential config options (#8455)
1 parent 21b47b1 commit d19573d

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

.changeset/gentle-waves-grab.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@graphql-codegen/client-preset': patch
3+
---
4+
5+
The client preset now allows the use of the following `config`:
6+
- `scalars`
7+
- `defaultScalarType`
8+
- `strictScalars`
9+
- `namingConvention`
10+
- `useTypeImports`
11+
- `skipTypename`
12+
- `arrayInputCoercion`

packages/presets/client/src/index.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,17 @@ export const preset: Types.OutputPreset<ClientPresetConfig> = {
6969
buildGeneratesSection: options => {
7070
const reexports: Array<string> = [];
7171

72+
// the `client` preset is restricting the config options inherited from `typescript`, `typescript-operations` and others.
73+
const forwardedConfig = {
74+
scalars: options.config.scalars,
75+
defaultScalarType: options.config.defaultScalarType,
76+
strictScalars: options.config.strictScalars,
77+
namingConvention: options.config.scalars,
78+
useTypeImports: options.config.useTypeImports,
79+
skipTypename: options.config.skipTypename,
80+
arrayInputCoercion: options.config.arrayInputCoercion,
81+
};
82+
7283
const visitor = new ClientSideBaseVisitor(options.schemaAst!, [], options.config, options.config);
7384
let fragmentMaskingConfig: FragmentMaskingConfig | null = null;
7485

@@ -176,7 +187,7 @@ export const preset: Types.OutputPreset<ClientPresetConfig> = {
176187
schema: options.schema,
177188
config: {
178189
inlineFragmentTypes: isMaskingFragments ? 'mask' : options.config['inlineFragmentTypes'],
179-
useTypeImports: options.config.useTypeImports,
190+
...forwardedConfig,
180191
},
181192
documents: sources,
182193
},

website/src/pages/docs/guides/react-vue.mdx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,23 @@ Feel free to continue playing with this demo project, available in all flavors,
475475

476476
<br />
477477

478+
## Config API
479+
480+
The `client` preset allows the following `config` options:
481+
482+
- [`scalars`](/plugins/typescript/typescript#config-api-reference): Extends or overrides the built-in scalars and custom GraphQL scalars to a custom type.
483+
- [`strictScalars`](/plugins/typescript/typescript#config-api-reference): If `scalars` are found in the schema that are not defined in scalars an error will be thrown during codegen.
484+
- [`namingConvention`](/plugins/typescript/typescript#config-api-reference): Available case functions in `change-case-all` are `camelCase`, `capitalCase`, `constantCase`, `dotCase`, `headerCase`, `noCase`, `paramCase`, `pascalCase`, `pathCase`, `sentenceCase`, `snakeCase`, `lowerCase`, `localeLowerCase`, `lowerCaseFirst`, `spongeCase`, `titleCase`, `upperCase`, `localeUpperCase` and `upperCaseFirst`
485+
- [`useTypeImports`](/plugins/typescript/typescript#config-api-reference): Will use `import type {}` rather than `import {}` when importing only types. This gives compatibility with TypeScript's `"importsNotUsedAsValues": "error"` option.
486+
- [`skipTypename`](/plugins/typescript/typescript#config-api-reference): Does not add `__typename` to the generated types, unless it was specified in the selection set.
487+
- [`arrayInputCoercion`](/plugins/typescript/typescript-operations#config-api-reference): The [GraphQL spec](https://spec.graphql.org/draft/#sel-FAHjBJFCAACE_Gh7d) allows arrays and a single primitive value for list input. This allows to deactivate that behavior to only accept arrays instead of single values.
488+
489+
<br />
490+
491+
---
492+
493+
<br />
494+
478495
## Appendix I: React Query with a custom fetcher setup
479496

480497
The use of `@tanstack/react-query` along with `graphql-request@^5` is highly recommended due to GraphQL Code Generator integration with `graphql-request@^5`:

0 commit comments

Comments
 (0)