What if your teams could speak the same data language without endless confusion?
Why Shared types across subgraphs in GraphQL? - Purpose & Use Cases
Imagine you have several teams building different parts of a big app, each with its own data. They try to keep their data types separate, but some types are actually the same across teams. Without sharing, each team copies and changes these types on their own.
This copying leads to confusion and mistakes. If one team updates a type, others might not know and keep using old versions. It becomes hard to keep data consistent, and fixing bugs takes a lot of time.
Shared types across subgraphs let teams define common data types once and use them everywhere. This keeps data consistent, reduces errors, and makes collaboration smooth because everyone agrees on the same type definitions.
type User { id: ID! name: String! }
type Product { id: ID! ownerName: String! }type User @shared { id: ID! name: String! }
extend type User @key(fields: "id") { id: ID! }It enables seamless data sharing and consistency across multiple teams and services working together.
In a large online store, the User type is shared across the shopping, payment, and review services, so all parts of the app recognize the same user data without conflicts.
Manual copying of types causes errors and confusion.
Shared types keep data consistent across subgraphs.
Teams collaborate better with a single source of truth for common types.