πŸ‘€ Our most exciting product launch yet πŸš€ Join us May 8th for Sanity Connect

GROQ Query Error - Error: `String Literal Expected`

1 replies
Last updated: Jan 21, 2023
Hi all, I need some help with a simple groq query. I am new to this, so having a little trouble figuring this out.

I have a list of services in the dataset that reference one of my 8 service sellers. I am trying to return all type=seller, with an added property of 'listedServices' that returns a total number of services that are referencing each particular seller.
I keep getting the error:
string literal expected
with the following query
*[_type == "seller"] {
  _id,
  name,
  sellerImageUrl,
  sellerRating,
  serviceCount: count(service[_type == "service" && _ref == ^._id])
}
Jan 21, 2023, 5:03 PM
I think you need to modify the serviceCount part of the query like so...

*[_type == "seller"] {
  _id,
  name,
  sellerImageUrl,
  sellerRating,
  "serviceCount": count(*[_type == "service" && references(^._id)])
}
I'm also a GROQ noob though, so apologies if that doesn't work/help!
Jan 21, 2023, 8:57 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?