midGraphQL
What is a GraphQL Fragment?
Updated Apr 28, 2026
Short answer
A Fragment is a reusable set of fields that can be shared across multiple queries to keep code DRY (Don't Repeat Yourself).
Deep explanation
Fragments let you construct sets of fields, and then include them in queries where you need to fetch the exact same data. They are heavily used in frontend component-based architectures (like React/Relay/Apollo).
Real-world example
Defining a fragment alongside a UI Component (e.g., UserProfile.js) so the component dictates exactly what data it needs to render.
Common mistakes
- Defining fragments but not tying them to the specific UI components that consume them, leading to over-fetching.
Follow-up questions
- What is an inline fragment?