You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: spec/Section 2 -- Language.md
+13-13Lines changed: 13 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -587,13 +587,9 @@ FragmentName : Name but not `on`
587
587
588
588
Fragments are the primary unit of composition in GraphQL.
589
589
590
-
Fragments allow for the reuse of common repeated selections of fields, reducing
591
-
duplicated text in the document. Inline Fragments can be used directly within a
592
-
selection to condition upon a type condition when querying against an interface
593
-
or union.
590
+
Fragments allow for the definition of selection sets that are colocated with the logic that requires those selections, making it easier to add and remove selections as needed.
594
591
595
-
For example, if we wanted to fetch some common information about mutual friends
596
-
as well as friends of some user:
592
+
For example, if we have some `friendProfile` logic that requires `id`, `name`, and `profilePic`, and we want to apply that logic to the mutual friends as well as friends of some user:
597
593
598
594
```graphql example
599
595
querynoFragments {
@@ -612,28 +608,32 @@ query noFragments {
612
608
}
613
609
```
614
610
615
-
The repeated fields could be extracted into a fragment and composed by a parent
616
-
fragment or operation.
611
+
The fields required of `friendProfile` can be extracted into a fragment and composed
612
+
by a parent fragment or operation.
617
613
618
614
```graphql example
619
615
querywithFragments {
620
616
user(id: 4) {
621
617
friends(first: 10) {
622
-
...friendFields
618
+
...friendProfileFragment
623
619
}
624
620
mutualFriends(first: 10) {
625
-
...friendFields
621
+
...friendProfileFragment
626
622
}
627
623
}
628
624
}
629
-
630
-
"Common fields for a user's friends."
631
-
fragmentfriendFieldsonUser {
625
+
```
626
+
```graphql example
627
+
"Fields required to display a friend's profile"
628
+
fragmentfriendProfileFragmentonUser {
632
629
id
633
630
name
634
631
profilePic(size: 50)
635
632
}
636
633
```
634
+
If `friendProfile` no longer needs `name`, the `name` field can be removed from
635
+
`friendProfileFragment` and it will no longer be fetched in both locations the
636
+
fragment is consumed.
637
637
638
638
Fragments are consumed by using the spread operator (`...`). All fields selected
639
639
by the fragment will be added to the field selection at the same level as the
0 commit comments