👀 Our most exciting product launch yet 🚀 Join us May 8th for Sanity Connect

What does an ellipsis (...) mean in a GROQ query?

21 replies
Last updated: Feb 8, 2021
What does
mean in a groq query like this… it is groq right?
export const pageQuery = `
  ...,
  content {
    ...,
    main {
      ...,
      modules[] {
        ...,
        ${moduleQuery}
      }
    }
  }
`;
being used here as well

const queryDraft = `*[_id == "${document}"]  {
    ...,
  }`;
Feb 8, 2021, 10:09 AM
I might be wrong, but I think it means that you'll get all of the content available for that query, but you can specify parts of it (in your case, you call it a model query)
Feb 8, 2021, 10:14 AM
user J
Okay, i was thinking that. Couldn’t find it in explicitly stated in the docs. thanks
Feb 8, 2021, 10:15 AM
Thanks Karin! Admittedly, it's a bit hidden in the docs :
A bare 
...
 is syntactic sugar for 
...@
, i.e. it inserts all attributes from the currently iterated element into the projection. For example, 
{..., "key": "value}
 generates an object with all of the object's original attributes in addition to the generated 
key
 attribute.
If multiple keys with the same name are given, then the latest key wins. The only exception is with the bare 
...
 syntactic sugar mentioned above, which is always evaluated first regardless of its position in the projection. For example, the projection 
{"name": "someName", ...}
 will replace the original 
name
 attribute of the object, if any.
Feb 8, 2021, 10:32 AM
Thanks Karin! Admittedly, it's a bit hidden in the docs :
A bare 
...
 is syntactic sugar for 
...@
, i.e. it inserts all attributes from the currently iterated element into the projection. For example, 
{..., "key": "value}
 generates an object with all of the object's original attributes in addition to the generated 
key
 attribute.
If multiple keys with the same name are given, then the latest key wins. The only exception is with the bare 
...
 syntactic sugar mentioned above, which is always evaluated first regardless of its position in the projection. For example, the projection 
{"name": "someName", ...}
 will replace the original 
name
 attribute of the object, if any.
Feb 8, 2021, 10:32 AM
user M
I’m trying to figure out why my queries are returning this object
Feb 8, 2021, 10:33 AM
when I’m trying to get this
Feb 8, 2021, 10:34 AM
Anything that references a document like page, product, collection, etc. It just returns a reference instead of the actual data. I’m tyring something like this, but it doesn’t return what I thought it would :
export const moduleQuery = `
  _type == 'productSlider' => {
    ...,
    products[] {
      ...,
      sanityProduct->
    }
  },
  _type == 'nestedPages' => {
    ...,
    page[] {
      ...,
      linkedPage->
    }
  }
`;

export const pageQuery = `
  ...,
  content {
    ...,
    main {
      ...,
      modules[] {
        ...,
        ${moduleQuery}
      }
    }
  }
`;
Feb 8, 2021, 10:35 AM
  const queryDraft = `*[_id == "${document}"]  {
    ...,
  }`;

  const queryPreviewPage = `*[_id == "${document}"]  {
    ${pageQuery}
  }`;
Feb 8, 2021, 10:35 AM
A few things to check:• Have you verified the module
_type
names are correct and at the correct level of nesting?• Are
sanityProduct
and
linkedPage
actual field names inside those modules?• Does it work if you fully write out one of those queries?
Feb 8, 2021, 10:43 AM
using
modules[] {}
is going to apply to everything within the modules array, right?
Feb 8, 2021, 10:45 AM
Correct 🙂
Feb 8, 2021, 10:54 AM
the objects im trying to get data from looks like this in the array
children: []
content: {images: {…}, main: {…}, shopify: {…}}
id: "93f8bcec-cd61-5e70-a515-1b6566d1ab31"
internal: {type: "SanityProduct", contentDigest: "148f4f057c418c84a59164fe2784bdb8", counter: 507, owner: "gatsby-source-sanity"}
parent: null
_createdAt: "2021-01-13T08:12:57Z"
_id: "1716036108354"
_rev: "7x5hkJBuoJKga49kaU2D2o"
_type: "product"
_updatedAt: "2021-02-03T06:11:56Z"
I’m trying this query, you were right about double checking names, but still nothing

 _type == 'productSlider' => {
    ...,
    products[] {
      ...,
      product->
    }
  },

Feb 8, 2021, 10:56 AM
does that query make sense?
Feb 8, 2021, 10:57 AM
But i’m just getting a ref string back because the expanding reference isn’t working
Feb 8, 2021, 10:59 AM
aiight
Feb 8, 2021, 11:03 AM
do previews
Feb 8, 2021, 11:03 AM
aiight
Feb 8, 2021, 11:03 AM
on about
Feb 8, 2021, 11:04 AM
You could try
products[]->
instead of
products[]
,or
_type == "product" => @->
inside of
products[]
.
Feb 8, 2021, 11:07 AM
okay products[] -> did work! Could I do a more general one and do modules[] -> and just get all teh data from every module?
Feb 8, 2021, 11:08 AM
It works, thank you!
Feb 8, 2021, 11:10 AM

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?