What if you could ask for exactly what you want from mixed data without sorting it yourself?
Why Inline fragments in GraphQL? - Purpose & Use Cases
Imagine you have a big box of mixed toys: cars, dolls, and blocks. You want to list only the cars with their special features, but you have to look at each toy one by one and guess if it is a car before writing down its details.
Doing this by hand is slow and confusing. You might miss some cars or mix up details from dolls or blocks. It's hard to keep track and easy to make mistakes when sorting and describing each toy separately.
Inline fragments let you tell the system exactly how to pick and show details for each type inside a mixed group. You write one query that says, "If this is a car, show these features," and it automatically skips the rest. This saves time and avoids errors.
query { toys { id name ... on Car { wheels engine } ... on Doll { hairColor } } }query { toys { id name ... on Car { wheels engine } } }Inline fragments make it easy to get just the right details from mixed data without extra work or confusion.
When building a shopping app, you can fetch different product types in one request and show only the relevant info for each, like size for clothes and battery life for electronics.
Manual filtering of mixed data is slow and error-prone.
Inline fragments let you specify type-based selections inside one query.
This makes data fetching cleaner, faster, and less confusing.