Skip to content

Commit a67e1c9

Browse files
SheW0lfSashko Stubailo
authored and
Sashko Stubailo
committed
Document default values for query variables graphql#294 (graphql#296)
* added a default variable paragraph to the documentation * Updated the Default Variables section of the documentation * Update Learn-Queries.md
1 parent c43e335 commit a67e1c9

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

site/learn/Learn-Queries.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,23 @@ Variable definitions can be optional or required. In the case above, since there
165165
To learn more about the syntax for these variable definitions, it's useful to learn the GraphQL schema language. The schema language is explained in detail on the Schema page.
166166

167167

168+
### Default variables
169+
170+
Default values can also be assigned to the variables in the query by adding the default value after the type declaration.
171+
172+
```graphql
173+
query HeroNameAndFriends($episode: Episode = "JEDI") {
174+
hero(episode: $episode) {
175+
name
176+
friends {
177+
name
178+
}
179+
}
180+
}
181+
```
182+
183+
When default values are provided for all variables, you can call the query without passing any variables. If any variables are passed as part of the variables dictionary, they will override the defaults.
184+
168185
## Operation name
169186

170187
One thing we also saw in the example above is that our query has acquired an _operation name_. 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)