đź”® Sanity Create is here. Writing is reinvented. Try now, no developer setup

Understanding the differences between Groq and GraphQL in Sanity.io

4 replies
Last updated: May 27, 2023
Hi! We're pretty close to choosing Sanity for our next project, but out team has hit 1 challenge using GROQ Vision that I'm trying to better understand. With other CMS using GraphQL Playground, it's super simple to construct queries from scratch since included with the playground is usually schema documentation and autocomplete. Does the Vision interface have anything like that to help generate the request?
May 24, 2023, 10:26 PM
Hi (Removed Name),
The thing is, that the Vision tool isn't operating on GraphQL -- it's for the Groq query language so useful in all areas of Sanity .

also lets you deploy your project's GraphQL API, and there, any GraphQL playground is able to introspect that api's GraphQL schema to generate autocompletion and that 'Documentation' -- which is what they all do, including Sanity's own GraphQL playground.
I'm putting a screenshot below, taken just now of Sanity's playground on a dev project, showing as many features as can be in the shot; the field list standing in for the autocomplete which uses the same introspected information.

I'm also giving you links with include a view on why Groq was chosen for work inside Sanity. It's brief, powerful, easily learned, can be used in one-line fragments which attune many features and screens, and so forth.

Both GraphQL and Groq are fully present and capable in Sanity, each for its own best uses.

May 25, 2023, 3:25 AM
user Q
Thank you for that very helpful response! I have actually liked using Groq over GraphQL for a couple reasons (primarily the reshaping capability), and I think my curiosity is more if we can somehow achieve those same Autocomplete/Introspection features with Groq/Vision?
May 25, 2023, 11:52 AM
Hi again, (Removed Name), and it's a reasonable question to ask.
I haven't been able to find anything that does this directly. There was a GitHub conversation some time ago which suggested an undocumented feature to get GraphQL SDL or JSON from a dataset, but that seems not to have gone forward, as when I attempted it, the link asked for a feature not existing now on the dataset, and the api didn't appear to have the feature.

I think the solution I suggested, using Vision on your deployed GraphQL API, is the way to get such a visualizaion of schema/s, also with auto-lookup of data names by filling in part of a query -- if such abilities seem useful.

Of a practical mind, them, don't tool abilities tend to show up where there's need for them? Sanity has very many useful tools, and given introspection in Groq views isn't among them, perhaps one should consider how needful it is in practice.

One of Sanity's great advantages, if it isn't indeed the central one, is componentized data. This means each individual schema is simple enough, especially on the side of easily seeing its data names.

And in Groq, you don't have the GraphQL challenges with discovering layers of internally made-up querying labels, or ways nodes need to be accessed for different purposes, or etc., which are the real problems introspected documentation tries to answer.

In Groq, you just write what you need, maybe with a few array or dereferencing indications, and you have what you wanted, with Vision letting you see how to work out and verify any details.

So, I said 'practical', and I guess that's what this is, no? And a definite smile, then.

(Removed Name), from your questions, I'd like to think you and your team will enjoy Sanity. It's as good as software gets, experience might say, and has a very definite sense of being solidly well engineered.

This new announcement, with interesting short video, might hint at just how far they intend to take it...

(Removed Name)
May 26, 2023, 4:19 AM
user Q
Thank you again for a very thorough answer! We are also feeling Sanity will be a great product for us—every aspect thus far seems to be very well thought through. Our team will have to weigh the pros/cons of Groq vs GraphQL now, but great to have a better understanding of what those are and that Sanity can serve us well either way.
May 27, 2023, 12:48 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?