😎 Discover cool tips and tricks for customization in our next Developer Deep Dive virtual event - sign up now!

Is it Possible to Exclude Data from a GROQ Query / Request?

5 replies
Last updated: Jul 30, 2021
Is it possible to exlude data in the groq request? Right now I’m doing the following to remove data, but i guess it just gets overwritten and still queries the data in the first place? I need everything except all data from `cmsvisual`:
*[_type == 'projects'] {
  ..., "cmsvisual": ""
}

Jul 30, 2021, 4:07 PM
Not at the moment. We’ve been thinking about ways to implement it, but for now you’ll have to explicitly name everything you want
Jul 30, 2021, 4:09 PM
its a bit unhandy, as by naming everything i need, if a new object is added to a schema, i need to update all groq request among the whole frontend. So +1 for this feature 🙂
Jul 30, 2021, 4:12 PM
You can, however, use
null
instead of
""
. In JavaScript,
null
and
undefined
both work as an absent value, so
project.cmsvisual
will evaluate to one of those regardless of whether it’s in the object or not.
Jul 30, 2021, 4:14 PM
Thanks! Just out of curiosity, it will still get queried on the api side, which would add time to query duration, right?
Jul 30, 2021, 4:15 PM
Yes, in the sense that the entire document is always fetched from the underlying document storage, then pruned during query execution.
Jul 30, 2021, 4:19 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?