Skip to content

Commit 6b01b11

Browse files
committed
GraphQL: Dropdown/Button Group fields
1 parent 555f3f9 commit 6b01b11

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed

docs/5.x/reference/field-types/button-group.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ The field works best with a limited number of visually distinct options.
3737

3838
## Development
3939

40-
Button group fields share the same template and query capabilities with [dropdown fields](dropdown.md).
40+
Button group fields share template, query, and GraphQL capabilities with [dropdown fields](dropdown.md).

docs/5.x/reference/field-types/dropdown.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,71 @@ If you have an element form, such as an [entry form](kb:entry-form), that needs
138138
{% endfor %}
139139
</select>
140140
```
141+
142+
### GraphQL
143+
144+
Dropdown fields (and the similar [button group](button-group.md) and [radio buttons](radio-buttons.md) fields) return a single string (or `null`) when selected in a GraphQL query:
145+
146+
::: code
147+
```graphql{7} Query
148+
query Reviews {
149+
entries(section: "reviews") {
150+
title
151+
postDate
152+
153+
... on review_Entry {
154+
sentiment
155+
}
156+
}
157+
}
158+
```
159+
```json{7,12,17,22} Response
160+
{
161+
"data": {
162+
"entries": [
163+
{
164+
"title": "Meh…",
165+
"postDate": "2025-05-07T10:30:00-07:00",
166+
"sentiment": "neutral"
167+
},
168+
{
169+
"title": "Undecided",
170+
"postDate": "2025-05-07T10:20:00-07:00",
171+
"sentiment": null
172+
},
173+
{
174+
"title": "Disappointed!",
175+
"postDate": "2025-05-07T10:10:00-07:00",
176+
"sentiment": "miserable"
177+
},
178+
{
179+
"title": "Out-of-this-world!",
180+
"postDate": "2025-05-07T10:00:00-07:00",
181+
"sentiment": "awesome"
182+
}
183+
]
184+
}
185+
}
186+
```
187+
:::
188+
189+
Fields can also be used as query arguments:
190+
191+
::: code
192+
```graphql Query
193+
query ReviewTally {
194+
positive: entryCount(section: "reviews", sentiment: "awesome")
195+
negative: entryCount(section: "reviews", sentiment: "miserable")
196+
impartial: entryCount(section: "reviews", sentiment: ["neutral", null])
197+
}
198+
```
199+
```json Response
200+
{
201+
"data": {
202+
"positive": 1,
203+
"negative": 1,
204+
"impartial": 2
205+
}
206+
}
207+
```
208+
:::

0 commit comments

Comments
 (0)