gatsby-source-sanity
gatsby-source-sanity copied to clipboard
Group on fields in nested object structures doesn't seem to work
Let's say you want to group posts by tags.
types: [
...schemaTypes,
{
name: 'post',
type: 'document',
title: 'Post',
fields: [
{
name: 'title',
type: 'string',
title: 'Title',
},
{
name: 'tags',
type: 'array',
title: 'Tags',
of: [
{ type: 'reference', to: [{type: 'tag'}]}
]
},
]
},
{
name: 'tag',
type: 'document',
title: 'Tag',
fields: [
{
name: 'title',
type: 'string',
title: 'Title',
},
]
}
])
This results in either

or

@kmelve What is the correct way to do this? Both of these attempts to group by an array of objects. Even the correct behavior here would not make sense. What would be the natural and correct way to express this in GraphQL?
Here's the documentation, and some more documentation for Gatsby, and here's an example.
_raw fields are of JSON type. You can't group on JSON fields. Is this also a problem if querying an array or string field?
Oh, I see. In the second example, you are querying tags____NODE, which I am surprised even exists - this sounds like a Gatsby bug. You are also trying to group by something which is an object type, whereas all the documentation examples group by simple values (strings). I'm not sure what you are trying to achieve is actually possible in Gatsby (basically group(field: "tags.title"))
Oh, so ___ actually means "nested", so I suppose this would actually be group(field: "tags___title") or group(field: "tags___id")?
Yes, that's my understanding too.
Did you try the tags___title variant?
have we solved this or does it still need prioritising?
I think this will be solved with the next release.
Next release of Gatsby or us?
Any updates on this yet, please? 😊