Watch a live product demo 👀 See how Sanity powers richer commerce experiences

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

The Sanity Composable Content Cloud is the 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.

Categorized in

Related answers

Get more help in the community Slack

TopicCategoriesFeaturedRepliesLast Updated
After adding the subtitle and running this code npm run graphql-deploy It does nothingSep 15, 2020
how to limit a reference to just one entry in Studio reference input side versus the default as-many-entries-as-you-fill-in-an-array...Sep 18, 2020
Is it possible to fetch more than one "_type" using GROQ?Nov 2, 2020
I want to add a view with the Structure builder (S.view.component) where I list similar documents based on the title. What...Sep 23, 2020
Is there a structure builder example where the format of each preview for the document list is modified?Feb 3, 2021
I have an array of references to a country schema type but it always just returns NULL values for meJan 30, 2021
Hi, I need help with a query for getting the url of an image asset. Here is what I've been trying, but I only get the _ref...Dec 1, 2020
Sanity UI looks brilliant :smiley: Is something like the current date picker possible at the moment? I’m not sure if anicon...Dec 21, 2020
Hey everyone. I have been coding and may have potentially accidentally deleted something. Does anyone know how to resolve...Dec 26, 2020
Hello everyone and happy new year :raised_hands::skin-tone-2:, I have a problem with outputting Portable Text :disappointed:...Jan 1, 2021

Related contributions

Clean Next.js + Sanity app
- Template

Official(made by Sanity team)

A clean example of Next.js with embedded Sanity ready for recomposition.

Cody Olsen
Go to Clean Next.js + Sanity app

Blog with Built-in Content Editing
- Template

Official(made by Sanity team)

A Sanity-powered blog with built-in content editing and instant previews.

Go to Blog with Built-in Content Editing