Basic Queries: Part 1
Below is a basic GraphQL query.
{
graph {
chat {
_id
message
}
}
}
Basic queries must be enclosed in the following pattern, { graph { } }
. The body of your query goes inside of the inner curly braces.
To query a collection, simply include the name of that collection, followed by curly braces with the names of all the predicates you want to display listed. For example, in the above query, the results would return all chat subject ids and chat/message
s.
If a predicate, like chat/person
is of type ref
, you can continue to follow the relationship by opening up a new set of curly braces, and listing any person predicates you want displayed.
For example:
{
graph {
chat {
_id
message
person {
_id
handle
}
}
}
}
Multiple top-level queries can be included in a single query, for example the below query selects all chats, artists, and persons.
{
graph {
chat {
_id
message
}
artist {
name
}
person {
handle
fullName
}
}
}
Also note that none of the predicates are namespaced (i.e. handle
not person/handle
). In GraphQL, predicates cannot be namespaced, and you must query predicates that belong to the relevant collection.