Basic queries with GROQ
In this section, we are going to perform project-related GROQ queries. GROQ syntax can be used to interact with Sanity's API. Additionally, many of Sanity's integrations will be able to obtain information using this syntax.
Selecting all events
The first simple query we are going to run will select all events stored in the dataset.
By default, GROQ will set the order of the results to the id
field. The id
used in Sanity is the _id
key in the resulting array:
*[_type == "event"]
This query will return all event content in a JSON-formatted array as shown:
"result":[ Â Â 0:{ Â Â Â Â "_createdAt":"2020-04-15T22:17:50Z" Â Â Â Â "_id":"6ddd2730-9aca-46dd-a7fd-850ab306f7fb" Â Â Â Â "_rev":"JmIGD46Mad7O6ByZXl1tpF" Â Â Â Â "_type":"event" Â Â Â Â "_updatedAt...