What does an ellipsis (...) mean in a GROQ query?
21 replies
Last updated: Feb 8, 2021
D
What does
being used here as well
…mean in a groq query like this… it is groq right?
export const pageQuery = ` ..., content { ..., main { ..., modules[] { ..., ${moduleQuery} } } } `;
const queryDraft = `*[_id == "${document}"] { ..., }`;
Feb 8, 2021, 10:09 AM
J
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
C
user J
Okay, i was thinking that. Couldn’t find it in explicitly stated in the docs. thanksFeb 8, 2021, 10:15 AM
P
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 generatedkeyattribute.
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 originalnameattribute of the object, if any.
Feb 8, 2021, 10:32 AM
P
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 generatedkeyattribute.
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 originalnameattribute of the object, if any.
Feb 8, 2021, 10:32 AM
D
user M
I’m trying to figure out why my queries are returning this objectFeb 8, 2021, 10:33 AM
D
when I’m trying to get this
Feb 8, 2021, 10:34 AM
D
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
D
const queryDraft = `*[_id == "${document}"] { ..., }`;
const queryPreviewPage = `*[_id == "${document}"] { ${pageQuery} }`;
Feb 8, 2021, 10:35 AM
P
A few things to check:• Have you verified the module
_typenames are correct and at the correct level of nesting?• Are
sanityProductand
linkedPageactual field names inside those modules?• Does it work if you fully write out one of those queries?
Feb 8, 2021, 10:43 AM
D
using
modules[] {}is going to apply to everything within the modules array, right?
Feb 8, 2021, 10:45 AM
P
Correct 🙂
Feb 8, 2021, 10:54 AM
D
the objects im trying to get data from looks like this in the array
I’m trying this query, you were right about double checking names, but still nothing
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"
_type == 'productSlider' => { ..., products[] { ..., product-> } },
Feb 8, 2021, 10:56 AM
D
does that query make sense?
Feb 8, 2021, 10:57 AM
D
But i’m just getting a ref string back because the expanding reference isn’t working
Feb 8, 2021, 10:59 AM
D
aiight
Feb 8, 2021, 11:03 AM
D
do previews
Feb 8, 2021, 11:03 AM
D
aiight
Feb 8, 2021, 11:03 AM
D
on about
Feb 8, 2021, 11:04 AM
P
You could try
products[]->instead of
products[],or
_type == "product" => @->inside of
products[].
Feb 8, 2021, 11:07 AM
D
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
D
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.