Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ const config: CodegenConfig = {

## Breaking changes

1. Object types are no longer generated
### 1. Object types are no longer generated

Previously, Object types from the schema were generated via the `typescript` plugin, for example:

Expand All @@ -230,11 +230,11 @@ Now, Object types are no longer generated. This prevents accidental misuse of sc

If you need schema types for any reason, please generate them using the `typescript` plugin in a separate file.

2. Args types are no longer generated
### 2. Args types are no longer generated

Args types are only used for server use cases, so they are no longer generated for client use cases.

3. Scalar types are no longer generated as a reusable type
### 3. Scalar types are no longer generated as a reusable type

Previously, Scalar types from the schema were generated into an object and reused in Variables types:

Expand Down Expand Up @@ -271,13 +271,13 @@ export type UserVariables = Exact<{
}>
```

4. Input and Enum types are only generated when used
### 4. Input and Enum types are only generated when used

Previously, all Input and Enum types were generated, even if they were not used. This could increase bundle size when Enums that incur runtime cost (e.g. native TypeScript enum or const enum) are used.

Now, only Input and Enum types used in operations are generated.

5. `__typename` is only generated when used
### 5. `__typename` is only generated when used

Previously, `__typename` fields in Result types are generated as optional by default, even when they were not requested:

Expand Down Expand Up @@ -317,7 +317,7 @@ export type UserQuery = {
continue to use `skipTypeNameForRoot` and `nonOptionalTypename` options to configure expected type behaviours.
</Callout>

6. Document field types are generated to correctly match runtime expectations
### 6. Document field types are generated to correctly match runtime expectations

Previously, nullable fields in Result types were generated as optional by default:

Expand All @@ -340,7 +340,7 @@ export type UserQuery = {
}
```

7. Enum config options are consolidated and the default value is changed
### 7. Enum config options are consolidated and the default value is changed

Previously, there were 4 boolean options to set which Enum variant to generate. When combined, these options overrode one another, leading to unexpected and confusing behaviour.

Expand All @@ -354,7 +354,7 @@ Now, `enumType` is the only config option to use. The default has also been chan
| Native const | `export const enum UserRole { Admin = 'ADMIN', Customer = 'CUSTOMER' };` | `{constEnums:true}` | `{enumType:'native-const'}` |
| Native numeric | `export enum UserRole { Admin = 0, Customer = 1 }` | `{numericEnums:true}` | `{enumType:'native-numeric'}` |

8. `avoidOptionals` option is updated to only handle Operation types
### 8. `avoidOptionals` option is updated to only handle Operation types

Previously, `avoidOptionals` was shared with the [typescript plugin](https://the-guild.dev/graphql/codegen/plugins/typescript/typescript#avoidoptionals). As a result, some inner options did not affect Operation types (such as `avoidOptionals.resolvers`, `avoidOptionals.query`, `avoidOptionals.mutation`, `avoidOptionals.subscription`).

Expand All @@ -366,7 +366,7 @@ Now, there are only 3 inner options, and when enabled, each forces the respectiv

Note that the default is `false`, and you can still use `avoidOptionals:true` to turn on all options, without having to set each one individually.

9. `preResolveTypes` option is removed
### 9. `preResolveTypes` option is removed

The `preResolveTypes` option was used to generate Result types inline (`preResolveTypes:false`) or use the ones generated by the `typescript` plugin (`preResolveTypes:true`). This approach had several drawbacks:

Expand All @@ -378,21 +378,21 @@ The `preResolveTypes` option was used to generate Result types inline (`preResol

If you are seeing problems, please create an issue [here](https://github.com/dotansimha/graphql-code-generator/issues).

10. Legacy utility types are removed
### 10. Legacy utility types are removed

The following utility types have been removed:

- `Maybe`: used to handle nullability types of fields in Result types. However, field types have been pre-resolved and inlined for a long time, so this type is no longer needed.
- `InputMaybe`: used to handle nullability types of Input. Input types are now inlined, so this type is no longer needed.
- `MakeOptional`, `MakeMaybe` and `MakeEmpty`: used to handle `preResolveTypes:false`. However, `preResolveTypes` has been removed, so these types are no longer needed.

11. Make `unknown` the default type for custom scalars instead of `any`
### 11. Make `unknown` the default type for custom scalars instead of `any`

Previously, the default custom Scalars type was `any`, which bypassed typechecking.

Now, the default type is `unknown` to ensure data is handled carefully by users.

12. Make `string | number` the default type for the native `ID` scalar
### 12. Make `string | number` the default type for the native `ID` scalar

Previously, one set of default Scalar types was shared between client and server plugins via the `typescript` plugin dependency. This meant it was not possible to set the default for client, as it would complicate the server config, and vice versa. See this [PR for more details](https://github.com/dotansimha/graphql-code-generator/pull/9497).

Expand Down
Loading