GraphQL Codegen typescript-operations and client-preset v6 has been 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
This release is the result of the close collaboration between The Guild and Igor Kusakov from Yelp, with thoughtful input from the wider GraphQL community.
My DM is always open for ideas and feedback: X, LinkedIn, GraphQL Discord 🙂
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 plugin typescript-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:
- Make migration path from Apollo Tooling to GraphQL Codegen easier
- Set better defaults for scalar types
- Remove rarely used option:
preResolveTypes - Revamp shared options to better match client usage: avoidOptionals and
inputMaybeValue - 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 enumValues imports 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)
