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
2
votes
1 answer

How to use arithmetic operator to calculate sum

I have a review type with a rating field that contains a number from 1 to 5. Now I'd like to calculate the average rating. Relevant schema: { name: 'rating', title: 'Rating', validation: Rule => Rule.required(), type:…
jgillich
  • 71,459
  • 6
  • 57
  • 85
1
vote
0 answers

Data is not updated after changes in the Sanity Studio

I am quite new to Sanity v3 + Next.js v13. Everything works great on my test site, but I have a problem when I update a document (project) or add a new one in the Sanity Studio – these changes are not updated on the pages. I am still on localhost. I…
podeig
  • 2,597
  • 8
  • 36
  • 60
1
vote
1 answer

Unable to Style Sanity Content using BlockContent

guys I need some help regarding styling my sanity content, So the issue is I'm trying to style the code block, but I'm not able to do so, when I style other items like h1, h2, h3, etc. then the code block disappers and If I'm styling code block then…
1
vote
1 answer

How to dynamically create pages using sanity and next js?

I just watched this video on youtube, where we can see that a preview of the page is being instantly dynamically generated within the studio, while the person is adding the components randomly from the dropdown and editing its content. What I want…
1
vote
0 answers

How to find a document in Sanity (groq) that has a value between two numbers

How do you query for a document using GROQ when the document has a value e.g. Width and you want to query for all documents that have a width value between 500 and 700 for example. It seems there isn't a built in method to do this or maybe it's not…
mylesthe.dev
  • 9,565
  • 4
  • 23
  • 34
1
vote
3 answers

Error: Errors while building: ./node_modules/@floating-ui/dom/dist/floating-ui.dom.esm.js Module parse failed: Unexpected token (307:11)

Hi everyone hope you all doing good, I am trying to add a plugin to sanity and the plugin is sanity-plugin-order-documents .I have followed all the steps shown in the documentation step by step. I added "plugins": [ "order-documents" ], to…
1
vote
1 answer

New nextjs 13 next/image component not loading with sanity.io image

I'm trying to get a simple next/image component displaying properly but the images just won't load. I'm using nextjs 13 which was just released so this is a new version of the component. I'm using sanity.io on the back and my images are stored…
1
vote
0 answers

API Post request to sanity patch query takes upwards of 2 seconds to complete

I'm struggling to understand what could be causing a slow response from the server, upwards of 2 seconds for a simple patch. I've gone ahead and posted an example to help better illustrate the problem. Right now if you swipe right on a card, it will…
1
vote
1 answer

How to use query param as a variable in groq sanity query inside getServerSideprops in next js?

I'm trying to implement search fuctionality in my blog project but facing problem in using variable in groq query(sanity) inside getServersideprops. Here is my code import React from 'react' import { useRouter } from 'next/router' import type {…
1
vote
1 answer

How to query all images in an array?

I'm using nextjs/Sanity. Want to get all of the image types out of an array, but nothing is showing up and nothing is coming up in the console either. It's particularly everything within the current slug. Not sure if I have imagesQuery coded…
paparonnie
  • 170
  • 8
1
vote
3 answers

Generating static pages (0/8)TypeError: Cannot destructure property 'title' of 'post' as it is undefined

I'm developing a blog using nextJS & sanity. And I connected sanity with nextJS and it's perfectly working in development mode. But when I try to deploy in Vercel or build through the VSCode, it shows the below error. info - Generating static pages…
1
vote
1 answer

Having an issue pulling data from my sanity.io database in react native app. I can pull it in one section but not another

I am having an issue with this code for a bit now. I think the problem is in my useEffect hook with the "{ id: '' }". When I console.log this data from my sanity.io client, the data comes up as null. My "{ id: '' }" is supposed to reference the $id…
1
vote
1 answer

Unable to fetch tweets using groq/sanity

I'm doing a code-along for a twitter clone and am not able to get tweets. I'm using Sanity and can confirm the data is there, and is fetched w/o error on sanity client. I think the issue is with groq, I've uninstalled, reinstalled it, installed it…
AntH00
  • 13
  • 4
1
vote
1 answer

How can I conditionally render tabs depending on the value of a field of a GROQ query?

I have a GROQ query where the result is an array of documents, of which one of the fields, "fieldName", can contain "a", "b" or "c". If the array contains any with the value "a" then I want to display a Chakra-UI for it in the as…
Anthony
  • 317
  • 1
  • 5
  • 23
1
vote
1 answer

How to filter Sanity.io dataset based on a field on references

How to get all posts by a category slug in GROQ? You can see that a post is added to one or more categories. I would like to get all posts by a category slug to show the posts on a category page. I am new to Sanity.io's GROQ. All the tutorials I…
Ben Jonson
  • 565
  • 7
  • 22