Bird
0
0

How can you use fragments to conditionally select fields based on the runtime type of a union or interface?

hard📝 Application Q9 of 15
GraphQL - Queries
How can you use fragments to conditionally select fields based on the runtime type of a union or interface?
AUse inline fragments with <code>... on TypeName</code> inside the query
BUse named fragments without specifying type
CUse multiple queries for each type
DFragments cannot be used with unions or interfaces
Step-by-Step Solution
Solution:
  1. Step 1: Understand conditional selection in GraphQL

    Inline fragments allow selecting fields based on the runtime type of a union or interface.
  2. Step 2: Evaluate options

    Use inline fragments with ... on TypeName inside the query correctly describes using inline fragments with '... on TypeName' syntax.
  3. Final Answer:

    Use inline fragments with ... on TypeName inside the query -> Option A
  4. Quick Check:

    Inline fragments enable conditional fields by type [OK]
Quick Trick: Use inline fragments '... on TypeName' for conditional fields [OK]
Common Mistakes:
  • Using named fragments without type
  • Running multiple queries unnecessarily
  • Believing fragments can't work with unions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GraphQL Quizzes