Thanks @samwoolertonLW ! Glad to hear your having fun while slaying dragons.
For this example, I made an IceCreams
table with a flavor
field of type SWITCH
with three flavors.
So the best way to do this would be to query the table field to then populate a list. I personally don’t find my solution that pretty, but it totally works!
This is how it would look if I were to query the whole table, and get back its fields and field data.
Query
query {
table(name: "IceCreams") {
fields {
id
fieldType
fieldTypeAttributes {
...switchFrag
}
}
}
}
fragment switchFrag on SwitchFieldTypeAttributes {
listOptions
}
Results
{
"data": {
"table": {
"fields": [
{
"id": "5d69e7b3b3cf3d32ab57c34e",
"fieldType": "ID",
"fieldTypeAttributes": null
},
{
"id": "5d69e7b3b3cf3d30d757c34f",
"fieldType": "DATE",
"fieldTypeAttributes": {}
},
{
"id": "5d69e7b3b3cf3d120a57c352",
"fieldType": "DATE",
"fieldTypeAttributes": {}
},
{
"id": "5d69e7b3b3cf3d016057c358",
"fieldType": "RELATION",
"fieldTypeAttributes": null
},
{
"id": "5d82495126ecb9dc3f6192bd",
"fieldType": "SWITCH",
"fieldTypeAttributes": {
"listOptions": [
"vanilla",
"chocolate",
"mint chip"
]
}
}
]
}
}
}
Because different fields have different fieldTypeAttributes
we need to create a fragment to get used for EACH TYPE that we want to get back. In this case, we only cared about the SwitchFieldTypeAttributes
type.
You could also do this by querying the actual field using its ID. This would require that you collect the ID and store it, but is the most direct way of getting what you’re looking for.
Query
{
tableField(id: "5d82495126ecb9dc3f6192bd") {
fieldType
fieldTypeAttributes {
...switchFrag
}
}
}
fragment switchFrag on SwitchFieldTypeAttributes {
format
listOptions
}
Result
{
"data": {
"tableField": {
"fieldType": "SWITCH",
"fieldTypeAttributes": {
"format": "CUSTOM",
"listOptions": [
"vanilla",
"chocolate",
"mint chip"
]
}
}
}
}