Questions tagged [groq]

GROQ - Graph Oriented Query Language, is a general purpose query language and can query any collection of unstructured JSON-documents without any up-front configuration.

GROQ - Graph Oriented Query Language

GROQ is developed by SANITY.io as is used to query data either hosted with SANITY or self-hosted. You usually write the queries in Content Studio and display the data in your front-end (vue.js, react, angular etc.).

Join together information from several sets of documents. Stitch together a very specific response the exact fields you need.

  • Follow references
  • Relational joins on key-value data
  • Get exactly the data structures you need by reprojecting attributes
  • Bundle multiple queries in the same request and get it all cached.
  • Query on structured block text

Everything:

*

Movies released after 1979

*[_type == 'movie' && releaseYear > 1979]

… ordered by release year and only certain fields

*[_type == 'movie' && releaseYear >= 1979]
  | order(releaseYear) {
    _id, title, releaseYear
  }

Get actors and join in arrays of the titles of the movies they played in

*[_type == "person"]{
  _id, name,
  "movies":
    *[
      _type == "movie"
      && references(^._id)
    ].title
}
78 questions
0
votes
1 answer

How to filter API data in sanity.io using react.js?

Hello I am new to the community and learning how things work here. Please try to understand through my broken English. suppose there are 200 data in API, but I just wanted to pull any 4 random data to frontend. To be more clear the data are blog…
thebuggybug
  • 15
  • 1
  • 7
0
votes
1 answer

sanity-algolia get error when using pt::text

I'm trying to integrate algolia search with sanity CMS using the sanity-algolia library (ref https://www.sanity.io/plugins/sanity-algolia) But when i try to get the plain text from Portable Text rich text content using the pt::text function. i get…
Kim Vu
  • 584
  • 9
  • 25
0
votes
1 answer

Filter an array of dates (datetime) with GROQ (sanity) (React App)

I have a list of movies that could be shown more than once. I decided to provide a user with an option to select multiple dates for a single movie (sanity studio interface). The schema for movies is as follows: export default { name: 'movie', …
1 2 3 4 5
6