FormidableLabs / groqd

A schema-unaware, runtime and type-safe query builder for GROQ.
https://commerce.nearform.com/open-source/groqd
MIT License
221 stars 17 forks source link

Array with object with reference! #270

Open williamneves opened 4 months ago

williamneves commented 4 months ago

Is there an existing issue for this?

Code of Conduct

Question

I have this follow schema:

{
  name: "program",
  title: "Programa",
  description: "Etapas do programa",
  type: "array",
  of: [{
    type: "object",
    fields: [{
      name: "step",
      title: "Etapa",
      type: "string",
    },
    {
      name: "etd",
      title: "Tempo Estimado de duração",
      type: "number",
      initialValue: 5,
    },
    {
      name: "colaborador",
      title: "Colaborador",
      type: "reference",
      to: [{
        type: "colaborador"
      }],
    },
    ],
  },
  ],
},

and my problem is, I cant fetch with the colaborador reference, the query I have so far is:

q("*")
    .filter("_type == 'devocional'")
    .grab$({
      title: q.string(),
      musicas: q('musicas')
      .filter()
      .deref()
      .grab$({
        title: q.string()
      }),
      program: q.array(q.object({
        step: q.string(),
        eta: q.string(),
        colaborador: q('colaborador', {isArray: false}).
        filter()
        .grab$({
          name: q.string()
          })
      }))
    }),

And this is not fetching, and this the query generated:

*[_type == 'devocional']{title, "musicas": musicas[]->{title}, program}

And this is a response:

title: "Visita a uma prisão"
musicas: [...] 4 items
0: {...} 1 properties
title: "A Alegria"
1: {...} 1 properties
title: "Quão bom e Quão maravilhoso"
2: {...} 1 properties
title: "Ninguém explicada Deus"
3: {...} 1 properties
title: "Entra na minha casa"
program: [...] 6 items
0: {...} 3 properties
etd: 5
step: "Orção inicial - Convidar um colcaborador"
_key: "c94a88d3d7c8"
1: {...} 3 properties
step: "momento musical com Todos"
_key: "bd231ce27d9c"
etd: 10
2: {...} 3 properties
_key: "c5e179d96e2a702826a76f1cc05dbcf4"
etd: 10
step: "Participação Especial/ Dueto"```

No colaborador at the response.

Thanks!