GraphQL Codegen typescript-operations and client-preset v6 was released with a hollistic review of dependencies, config options, and plugin interoperability to improve Developer Experience for our users:
- Less generated code
- Better type correctness and defaults
- Fewer dependencies, and simpler setup
The main change
Previously, the low-level typescript plugin was used to generate all schema types, and the typescript-operations plugin referred to the schema types in its Input and Variables types. This approach led to a few problems:
- All schema types were generated, even if unused
- Impact: Unncessarily large generated files and extraneous types, which caused confusion to users.
- Client and server plugins were indirectly tied together
- Examples:
typescriptplugin's default options were created to work for both client and server, but not optimised for either. This meant users must eventually tweaked the default config for their client use case.- Any attempt to reduce the generated schema types most likely touch the
typescriptplugin, which impacted the server plugintypescript-resolvers, because they both relied on the same generated type.
- Impact: Slower feature turnaround, because contributors working on the client use case needed to tip-toe to avoid impacting the server use case.
- Examples:
- Ways to setup Codegen config were numerous, with some requiring external plugins/presets with fragile integration
- Impact: Verbose Codegen config, added dependencies to maintain e.g. import-types preset
Now, typescript-operations and client-preset v6 were built with fundamental changes to solve the mentioned problems:
- Generate schema types only when used
- Decouple completely from
typescriptandtypescript-resolvers - Improve Built-in support for setups commonly used by the community: one-file, multi-file, near-operation-file setups
Other changes
We also take the opportunity to make various improvements, and fix tricky bugs:
- Set better defaults for scalar types
- Remove rarely used option:
preResolveTypes - Revamp shared options to better match client usage:
avoidOptionalsandinputMaybeValue - Ensure result fields are never optional, unless deferred or conditional
- Improve typings for
@skip/@includedirectives - Fix errors silently failing by default
- Ensure consistent naming convention for
enumValuesimports and references - Change
client-presetdefault hash algorithm to SHA256 - Add usage warnings for internal utility types:
ExactandIncremental - Update dependencies to latest versions (some are now ESM-only)
