🔮 Sanity Create is here. Writing is reinvented. Try now, no developer setup

Discussion on using GROQ vs GraphQL for Sanity.io, with GROQ being recommended for its capabilities.

18 replies
Last updated: Apr 12, 2021
Hey all, happy Friday 😄 Just looking into Sanity and wondering: would you consider GraphQL to have first-class support? Or will the experience generally be smoother using GROQ? It's not a dealbreak either way.
Apr 9, 2021, 8:55 PM
GROQ is more capable than GraphQL in any setting, so I would definitely recommend using that over gql.
Apr 9, 2021, 11:27 PM
In that it's more sanity-aware? I haven't played with it yet
Apr 9, 2021, 11:28 PM
Install the vision plugin in the studio and you can try it out (I only wish there was autocompletion). You can use some pretty good filtering with GROQ.
You can have a play around on this site as well:
Apr 9, 2021, 11:33 PM
And there’s some pretty good docs here: https://www.sanity.io/docs/groq
Apr 9, 2021, 11:33 PM
Okay this is really helpful. Looking at the "Complex" variant at groq.dev, I can see what you're saying about its power. Just need to weigh whether that justifies eschewing all the tooling that comes with GraphQL (Typescript, React, etc)
Apr 9, 2021, 11:36 PM
It’s definitely more capable for Sanity than GraphQL. But even in general I find that it has the edge on some things, it’s more the tooling around it that gql takes. You can perform more operations on your queries with GROQ than gql. Unlike gql GROQ has a spread operator to grab all the fields (though it doesn’t resolve references).
Apr 9, 2021, 11:37 PM
Yeah for sure, gql has a lot more tooling support. Especially in the sense that it builds an API schema which offers up nice documentation, autocompletion and type generation.
Apr 9, 2021, 11:38 PM
Lots of good food for thought, thanks!
Apr 9, 2021, 11:40 PM
Using GraphQL with Sanity still works fine. The Gatsby plugin uses GraphQL.
Apr 9, 2021, 11:40 PM
No worries!
Apr 9, 2021, 11:40 PM
I only wish there was autocompletion.
should work in Vision, albeit it doesn’t appear to be context-aware.
Apr 10, 2021, 3:20 PM
I've tried that out of habit a few times and it doesn't seem to do anything for me 🤷‍♂️
Apr 10, 2021, 3:25 PM
Any chance you’re overriding that keybinding with TextExpander or something similar?
Apr 10, 2021, 3:28 PM
I don't even know what that is 😅 but it works in GraphiQL so I don't think so.
Apr 10, 2021, 3:29 PM
I'll give it another go next week when I work in the studio again
Apr 10, 2021, 3:30 PM
Eliot: I personally love GROQ. It just works—and works really well with Sanity. You don’t need to define a schema and can just query any JSON data with it. You can play around with the GROQ Arcade at https://groq.dev/ . Espen gave a recorded talk a few years ago that helps distinguish GROQ a bit. About 4 minutes in he points out exactly what Max said about autocompletion. There are also a few notes about why Sanity uses GROQ here .
As GROQ is a Sanity creation, the docs tend to be written using GROQ queries (outside of the docs that are specific to the
GraphQL API ).
There are plenty of people in this community using both GROQ and GraphQL so I think you’ll get great support either way.
Apr 10, 2021, 3:41 PM
Great info thanks! To me, defining a schema is an advantage from a code stability perspective. But I come from a non-JS background 😉
Apr 12, 2021, 1:56 PM
Understandable, and GROQ won’t mind at all (and as you may have already seen in your research, when using Sanity a schema will be a requirement).
Apr 12, 2021, 2:36 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?