Query returning empty array when trying to get articles from a collection.

9 replies
Last updated: Jul 25, 2023
I’m trying to make a query to get an
n
number of articles from a collection but is returning an array with 3 empty objects.
Jul 25, 2023, 9:11 PM
Initially I had the following query which returned an object with a property
articles
and the array inside:

const ARTICLE_BY_COLLECTION_QUERY = groq`
  *[_type == "articleCollection" && slug.current == $collection][0]{
  "articles": articles[0...$n]->{
    ${ARTICLE_FIELDS}
  }
}
`;

Jul 25, 2023, 9:12 PM
However I wanted to have an array returned from the articles so I tried doing this:

const ARTICLE_BY_COLLECTION_QUERY = groq`
  *[_type == "articleCollection" && slug.current == $collection][].articles[0...$n]->{
    _id
  }
`;
Jul 25, 2023, 9:13 PM
the query works as expected on the sanity vision but when making the actual query on the vue client it returns an empty array.
Jul 25, 2023, 9:14 PM
Any ideas why?
Jul 25, 2023, 9:14 PM
What version of the API are you using?
Jul 25, 2023, 9:26 PM
nvm somehow it’s working now 😅
Jul 25, 2023, 9:30 PM
thanks anyways!
Jul 25, 2023, 9:30 PM
I love when something decides to fix itself!
Jul 25, 2023, 9:33 PM
same!
Jul 25, 2023, 9:33 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?