Recall & Review
beginner
What is a fragment in GraphQL?
A fragment is a reusable piece of a query that lets you define a set of fields once and include them in multiple queries or mutations to avoid repetition.
Click to reveal answer
beginner
How do you define a fragment in GraphQL?
You define a fragment using the
fragment keyword, followed by a name, the type it applies to, and the fields inside curly braces. Example: fragment userFields on User { id name email }Click to reveal answer
beginner
How do you use a fragment inside a GraphQL query?
You include a fragment in a query by using three dots followed by the fragment name. Example:
{ user(id: 1) { ...userFields } }Click to reveal answer
intermediate
Why are fragments useful in GraphQL?
Fragments help keep queries clean and consistent by reusing field selections. They reduce errors and make it easier to update fields in many places at once.
Click to reveal answer
intermediate
Can fragments be used with different types in GraphQL?
Fragments are defined for a specific type. To reuse fields across different types, you can use interfaces or unions with fragments on those types, but a fragment itself applies to one type only.
Click to reveal answer
What keyword is used to define a fragment in GraphQL?
✗ Incorrect
The
fragment keyword defines reusable field selections in GraphQL.How do you include a fragment named
userFields inside a query?✗ Incorrect
You include a fragment by writing three dots followed by the fragment name, like
...userFields.Fragments in GraphQL help to:
✗ Incorrect
Fragments let you reuse sets of fields in queries to keep them clean and consistent.
Can a fragment be used on multiple different types directly?
✗ Incorrect
Fragments are defined for one type; to share fields across types, interfaces or unions are used.
Which of the following is a correct fragment definition?
✗ Incorrect
The correct syntax includes the fragment name, the type with 'on', and the fields inside braces.
Explain what GraphQL fragments are and how they help when writing queries.
Think about how you might copy-paste fields in many queries and how fragments solve that.
You got /4 concepts.
Describe the syntax to define and use a fragment in a GraphQL query.
Remember the three dots when including a fragment.
You got /5 concepts.