Bird
0
0

Why does GraphQL require inline fragments when querying union or interface types?

hard📝 Conceptual Q10 of 15
GraphQL - Queries
Why does GraphQL require inline fragments when querying union or interface types?
ABecause fields differ by type and must be selected conditionally
BBecause GraphQL does not support unions without fragments
CBecause inline fragments improve query performance
DBecause inline fragments define new types in the schema
Step-by-Step Solution
Solution:
  1. Step 1: Understand union/interface behavior

    Unions and interfaces can represent multiple types with different fields.
  2. Step 2: Explain need for inline fragments

    Inline fragments let you select fields only for the actual type returned, avoiding errors.
  3. Final Answer:

    Because fields differ by type and must be selected conditionally -> Option A
  4. Quick Check:

    Inline fragments = conditional field selection by type [OK]
Quick Trick: Inline fragments handle type-specific fields in unions/interfaces [OK]
Common Mistakes:
  • Thinking inline fragments create types
  • Assuming inline fragments improve performance
  • Believing unions can't be queried without fragments

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GraphQL Quizzes