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.
Previous
How do field resolvers work with the parent object in GraphQL?
Next
What is batch loading in GraphQL and how does it improve performance?
More GraphQL Questions
View all →- Intermediate What is the N+1 problem in GraphQL and how does DataLoader solve it?
- Intermediate What are persisted queries in GraphQL?
- Intermediate What is the difference between schema-first and code-first GraphQL approaches?
- Intermediate What are the pagination strategies in GraphQL?
- Intermediate How is authentication handled in GraphQL?