⬡ GraphQL
Beginner
What are inline fragments in GraphQL?
Answer
Inline fragments are used to conditionally select fields based on the concrete type of a field that is an interface or union. Instead of defining a named fragment, you embed it inline: { search(term: "cat") { ... on User { name email } ... on Post { title body } } }. This is essential when querying a field that can return multiple types (a union or interface). The __typename meta-field is often included alongside inline fragments so the client knows which type was returned and can render the correct component.