Fields
Fields is the attribute of an object, we can declare fields in query or mutation
For example given the following query:
{
hero {
name // Field
}
}
We have our field here: name
. As a result, GraphQL will returns the name
of this hero
object:
{
"data": {
"hero": {
"name": "R2-D2"
}
}
}
We can also make subselection of fields if we want to go a bit deeper:
{
hero {
name
# Queries can have comments!
friends {
name
}
}
}
Will results into
{
"data": {
"hero": {
"name": "R2-D2",
"friends": [
{
"name": "Luke Skywalker"
},
{
"name": "Han Solo"
},
{
"name": "Leia Organa"
}
]
}
}
}