GraphQL Fragments
ELI5 — The Vibe Check
GraphQL Fragments are reusable chunks of a query — like copy-pasting field selections without actually copy-pasting. If five different queries all need a user's name, email, and avatar, you define that once as a fragment and spread it everywhere. It's the DRY principle applied to your data fetching.
Real Talk
GraphQL Fragments are reusable units of query fields that can be included in multiple operations using the spread syntax (...FragmentName). They ensure consistent field selection across queries, reduce duplication, and enable collocated data requirements in component-based architectures. Fragment types must match the parent type.
When You'll Hear This
"Every component defines its own fragment — we compose them into the page query automatically." / "Fragments keep our 20 user-related queries consistent when we add a new field."
Related Terms
GraphQL
GraphQL is like ordering food where YOU specify exactly what you want on your plate.
GraphQL Directives
GraphQL Directives are like special annotations that modify how your query behaves — think of them as post-it notes on your query saying 'skip this field'