Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/presets/client/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @graphql-codegen/client-preset

## 5.1.0

### Minor Changes

- [#10459](https://github.com/dotansimha/graphql-code-generator/pull/10459) [`87184aa`](https://github.com/dotansimha/graphql-code-generator/commit/87184aa240cb6209e7b3ade13aa54da6ff0b3dff) Thanks [@eddeee888](https://github.com/eddeee888)! - Forward immutableTypes to client preset config

## 5.0.3

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/presets/client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@graphql-codegen/client-preset",
"version": "5.0.3",
"version": "5.1.0",
"description": "GraphQL Code Generator preset for client.",
"repository": {
"type": "git",
Expand Down
1 change: 1 addition & 0 deletions packages/presets/client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ export const preset: Types.OutputPreset<ClientPresetConfig> = {
onlyOperationTypes: options.config.onlyOperationTypes,
onlyEnums: options.config.onlyEnums,
customDirectives: options.config.customDirectives,
immutableTypes: options.config.immutableTypes,
};

const visitor = new ClientSideBaseVisitor(options.schemaAst, [], options.config, options.config);
Expand Down
81 changes: 81 additions & 0 deletions packages/presets/client/tests/client-preset.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3190,4 +3190,85 @@ export * from "./gql.js";`);

export { Color };`);
});

it('supports immutableTypes', async () => {
const { result } = await executeCodegen({
schema: [
/* GraphQL */ `
type Query {
user(id: ID!): User
}
type User {
id: ID!
name: String!
friends: [User!]!
}
`,
],
documents: [
/* GraphQL */ `
query Test_User {
user(id: "user-001") {
id
name
}
}
`,
],
generates: {
'out1/': {
preset,
config: {
immutableTypes: true,
},
},
},
});

const graphqlFile = result.find(file => file.filename === 'out1/graphql.ts');
expect(graphqlFile.content).toMatchInlineSnapshot(`
"/* eslint-disable */
import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core';
export type Maybe<T> = T | null;
export type InputMaybe<T> = T | null | undefined;
export type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] };
export type MakeOptional<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]?: Maybe<T[SubKey]> };
export type MakeMaybe<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]: Maybe<T[SubKey]> };
export type MakeEmpty<T extends { [key: string]: unknown }, K extends keyof T> = { [_ in K]?: never };
export type Incremental<T> = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never };
/** All built-in and custom scalars, mapped to their actual values */
export type Scalars = {
ID: { input: string; output: string; }
String: { input: string; output: string; }
Boolean: { input: boolean; output: boolean; }
Int: { input: number; output: number; }
Float: { input: number; output: number; }
};

export type Query = {
readonly __typename?: 'Query';
readonly user?: Maybe<User>;
};


export type QueryUserArgs = {
id: Scalars['ID']['input'];
};

export type User = {
readonly __typename?: 'User';
readonly friends: ReadonlyArray<User>;
readonly id: Scalars['ID']['output'];
readonly name: Scalars['String']['output'];
};

export type Test_UserQueryVariables = Exact<{ [key: string]: never; }>;


export type Test_UserQuery = { readonly __typename?: 'Query', readonly user?: { readonly __typename?: 'User', readonly id: string, readonly name: string } | null };


export const Test_UserDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"Test_User"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"user"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"id"},"value":{"kind":"StringValue","value":"user-001","block":false}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}}]}}]}}]} as unknown as DocumentNode<Test_UserQuery, Test_UserQueryVariables>;"
`);
});
});
2 changes: 1 addition & 1 deletion website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@graphql-codegen/c-sharp": "4.3.1",
"@graphql-codegen/c-sharp-operations": "2.3.1",
"@graphql-codegen/cli": "6.0.0",
"@graphql-codegen/client-preset": "5.0.3",
"@graphql-codegen/client-preset": "5.1.0",
"@graphql-codegen/core": "5.0.0",
"@graphql-codegen/flow": "2.3.6",
"@graphql-codegen/flow-operations": "2.3.6",
Expand Down
1 change: 1 addition & 0 deletions website/src/pages/plugins/presets/preset-client.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ The `client` preset allows the following `config` options:
- [`strictScalars`](/plugins/typescript/typescript#strictscalars): If `scalars` are found in the schema that are not defined in scalars an error will be thrown during codegen.
- [`namingConvention`](/plugins/typescript/typescript#namingconvention): 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`.
- [`useTypeImports`](/plugins/typescript/typescript#usetypeimports): Will use `import type {}` rather than `import {}` when importing only types. This gives compatibility with TypeScript's [`"importsNotUsedAsValues": "error"`](https://www.typescriptlang.org/tsconfig#importsNotUsedAsValues) option.
- [`immutableTypes`](/plugins/typescript/typescript#immutabletypes): Generates immutable types by adding `readonly` to properties and `ReadonlyArray` for lists.
- [`skipTypename`](/plugins/typescript/typescript#skiptypename): Does not add `__typename` to the generated types, unless it was specified in the selection set.
- [`arrayInputCoercion`](/plugins/typescript/typescript-operations#arrayinputcoercion): 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.
- [`enumsAsTypes`](/plugins/typescript/typescript#enumsastypes): Generates enum as TypeScript string union `type` instead of an `enum`. Useful if you wish to generate `.d.ts` declaration file instead of `.ts`, or if you want to avoid using TypeScript enums due to bundle size concerns.
Expand Down
Loading
Loading