Bird
0
0

What is the main purpose of using fragments in GraphQL queries?

easy📝 Conceptual Q11 of 15
GraphQL - Queries
What is the main purpose of using fragments in GraphQL queries?
ATo define variables for queries
BTo reuse a set of fields in multiple queries or parts of a query
CTo create mutations for updating data
DTo sort the results of a query
Step-by-Step Solution
Solution:
  1. Step 1: Understand what fragments do

    Fragments allow you to save a group of fields so you can use them repeatedly without rewriting.
  2. Step 2: Identify the purpose in queries

    This helps keep queries clean and avoids repetition by reusing the same field selections.
  3. Final Answer:

    To reuse a set of fields in multiple queries or parts of a query -> Option B
  4. Quick Check:

    Fragments = reusable fields [OK]
Quick Trick: Fragments save repeated fields for reuse in queries [OK]
Common Mistakes:
  • Confusing fragments with variables
  • Thinking fragments sort or filter data
  • Using fragments to define mutations

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GraphQL Quizzes