Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf286937

Browse files
a-b-r-o-w-nstubailo
authored andcommitted
link to variables section in fragments section (graphql#541)
* link to variables section in fragments section* add fragment with argument example* reference variables instead of arguments
1 parenta9f106d commitf286937

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

‎site/learn/Learn-Queries.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,34 @@ fragment comparisonFields on Character {
124124

125125
You can see how the above query would be pretty repetitive if the fields were repeated. The concept of fragments is frequently used to split complicated application data requirements into smaller chunks, especially when you need to combine lots of UI components with different fragments into one initial data fetch.
126126

127+
###Using variables inside fragments
128+
129+
It is possible for fragments to access variables declared in the query or mutation. See[variables](learn/queries/#variables).
130+
131+
```graphql
132+
# { "graphiql": true }
133+
queryHeroComparison($first:Int =3) {
134+
leftComparison:hero(episode: EMPIRE) {
135+
...comparisonFields
136+
}
137+
rightComparison:hero(episode: JEDI) {
138+
...comparisonFields
139+
}
140+
}
141+
142+
fragmentcomparisonFieldsonCharacter {
143+
name
144+
friendsConnection(first:$first) {
145+
totalCount
146+
edges {
147+
node {
148+
name
149+
}
150+
}
151+
}
152+
}
153+
```
154+
127155
##Operation name
128156

129157
Up until now, we have been using a shorthand syntax where we omit both the`query` keyword and the query name, but in production apps it's useful to use these to make our code less ambiguous.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp