๐Ÿ”ฎ Sanity Create is here. Writing is reinvented. Try now, no developer setup

Issue with fetching data from an array of references and non-references in a groq query.

3 replies
Last updated: Dec 14, 2023
Hey! I'm trying to create a groq query that fetches data from an array of both references and not references.
This is what I currently have, but the not-references returns null, and if I remove the -> after contentLoggedin[], all the other entries return null!

contentLoggedIn[] -> {
    _type == 'staticSlider' => {
      header {
        callToAction {
      items[] -> {
        image {
          "asset": {
            "url": asset->url
    _type == 'dynamicSlider' => {
Basically, the dynamicSlider type returns null...
Dec 13, 2023, 1:33 PM
What does the schema for this look like?
Dec 13, 2023, 5:39 PM
user M
and thanks for the response ๐Ÿ™‚
This is the schema for that specific type:

  name: 'contentLoggedIn',
  type: 'array',
  title: 'Content for a logged in user',
  description: 'Create, add and order the content of this landing page.',
  of: [
      type: 'reference',
      title: 'Reusable Static Slider or Banner',
      to: [{ type: 'staticSlider' }, { type: 'banner' }, { type: 'twoTileBanner' }],
    { type: 'dynamicSlider' },
And the dynamic slider is just an object with a simple object called "content" which has title and value, like this:

  name: 'dynamicSlider',
  type: 'object',
  title: 'Dynamic Slider',
  fields: [
      name: 'content',
      type: 'string',
      title: 'Dynamic Content',
      description: 'Choose what dynamic content to display.',
      options: {
        list: [
          { title: 'Popular items', value: 'popularItems' },
          { title: 'Favourite items', value: 'favouriteItems' },
          { title: 'Recommended items', value: 'recommendedItems' },
        layout: 'radio',
Whereas the other items in the array of contentLoggedIn are references.
Dec 14, 2023, 12:25 PM
I figured it out ๐Ÿ™‚
Dec 14, 2023, 2:20 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?