⬡ GraphQL Intermediate

What are schema extensions in GraphQL?

Answer

Schema extensions allow you to add fields or types to an existing schema without modifying the original definition. Use the extend keyword: extend type User { preferredLanguage: String } adds a new field to the User type. This is crucial in modular schema design where different files or modules own different parts of the schema and extend shared types. In Apollo Federation, the extend type Query pattern lets each subgraph add its own fields to the root Query type. Extensions can also add interfaces, directives, and new types to the schema, enabling clean separation of concerns without tight coupling.