6

I have a schema type Page which has an array of blocks:

{
  title: 'Page',
  name: 'page',
  type: 'document',
  fields: [
    ...
    {
      title: 'Blocks',
      name: 'blocks',
      type: 'array',
      of: [
        {type: 'tileGrid'},
        {type: 'otherType'}
      ],
      options: {
        editModal: 'fullscreen'
      }
    }
  ]
}

The type tileGrid has the following fields:

{
      title: 'Tiles',
      name: 'tiles',
      type: 'array',
      of:  [{
        type: 'reference',
        to: [
          {type: 'tile'}
        ]
      }]
}

So the tile type is deeply nested page.blocks[].tiles[].tile. How can I query page and fill in the tile references in the same query?

dotnetCarpenter
  • 10,019
  • 6
  • 32
  • 54
Slem
  • 108
  • 1
  • 6

1 Answers1

6

Since tile is a reference, you need the dereferencing operator, rather than the dot operator. This should work: page.blocks[].tiles[]->.

svale
  • 264
  • 1
  • 3
  • How would you structure the query? This is what I've tried: `*[_type == "page"]{_id, name, route, blocks, blocks[].tiles[]->tile}}` – Slem Jan 16 '18 at 12:51
  • Whenever you build complex chains or arbitrary queries like that, you probably have to name that field. Something like this: `*[_type == "page"]{_id, name, route, "blocks": blocks[].tiles[]->}}` (Remove the `tile` after the dereferencing operator, this would extract the field "tile" from whatever is referred to, while just adding the arrow expands whatever is pointed to by the reference) – svale Jan 16 '18 at 14:38