GraphQL Code Generator just released a major update to improve type correctness and usability for both Federation and standard GraphQL server architecture. This milestone, the result of a 9-month long journey, closes many long-standing reported issues and serves as the foundation to help us move forward faster.

Migration Guide

  • Federation entity’s resolver types correctly reflect the parent may come from a different subgraph (via __resolveReference) or from the same subgraph. Use mappers to explicitly set the expected use case to help with typing. For example:
// If you are only resolving fields through `__resolveReference`, then explicitly set the reference type: import { FederationReferenceTypes } from "./types.generated"; export type UserMapper = FederationReferenceTypes["User"] // If your current subgraph returns a different interface to `__resolveReference`, include both in the mapper, and handle both cases in subsequent resolvers: import { UserTypeFromDatabase } from "./your-database-type"; import { FederationReferenceTypes } from "./types.generated"; export type UserMapper = | UserTypeFromDatabase | FederationReferenceTypes["User"] // If you want to standardise the mapper interface (which means you may need to resolve for `UserTypeFromDatabase` in `__resolveReference`): import { UserTypeFromDatabase } from "./your-database-type"; export type UserMapper = UserTypeFromDatabase
  • If you have implemented non-meta resolvers in Interfaces, remove them as they are never called. Generated types have been updated to reflect this.
  • If you have implemented __isTypeOf resolvers for types that are not Interface implementing types or Union member types, remove them as they are never called. Generated types have been updated to reflect this.

Breaking Changes

  • FederationReferenceTypes is generated instead of inlining __resolveReference types to improve usability with mappers
  • Fixed mappers for Federation use case
  • Federation __resolveReference resolver is available for Interfaces
  • Fixed Federation directives types such as @external, @requires, etc.
  • Interface non-meta resolvers are no longer generated.
  • __isTypeOf resolver is no longer generated for output types which are not Interface implementing types or Union member types
  • UnwrappedObject type is no longer generated
  • Record<PropertyKey, never> is generated instead of {} for empty object types
  • Deprecated generateInternalResolversIfNeeded option. Codegen decides whether to generate meta resolvers to match the spec
  • Deprecated watchConfig, dedupeFragments and noGraphQLTag legacy options
  • Dropped Node 18 support
  • Refactored internal type overrides that has been causing confusion and frustration to contributors. This impacts downstream plugins that extend base typescript and typescript-resolvers plugins.

Other Changes

  • Partial success writes successful generation to file
  • Migrated from Jest to Vitest

Summary

This major release strengthens type safety for both Federation and standard GraphQL servers, simplifies configs, and improves contributor experience. Thanks to community feedback and collaboration, GraphQL Code Generator is more reliable and easier to extend than ever.

If you spot problems or have unsupported use cases, please create issues here to help us track and continue to make improvements!

Last updated on