Hello!
I am currently building a website for a museum, and for their events page, I would like to implement a filtering system, based on the starting date, the type of event, etc...
I have added all that data in the config and I am now in the process of writing the Graphql queries with the filtering options.
To create a nicer user interface for the editors, I have added some
Tabsfields. One of those tabs is called
informationand whenever I try to use a value in the
whereclausule, that is inside the tab, it gives me the following error:
The following path cannot be queried: event_type. I have moved it out of the tabs and then it works, but this makes the UI for the editor very cluttered, as there is a lot of data to input that I'd like to keep organized.
Is there a way to use nested fields in the
whereclausule?
The field structure looks as follows:
{
type: 'tabs',
label: false,
tabs: [
{
name: 'information',
label: 'Information',
fields: [
{
type: 'row',
fields: [
{
type: 'number',
name: 'start_age',
label: 'Youngest recommended age',
},
{
type: 'number',
name: 'end_age',
label: 'Oldest recommended age',
},
],
},
{
type: 'relationship',
name: 'event_type',
label: 'Event type',
relationTo: 'eventType',
hasMany: true,
required: true,
}
]
},
]
}And the Graphql query looks as follows:
query Events($page: Int, $locale: LocaleInputType, $eventType: String, ) {
Events(
limit: 2
page: $page
locale: $locale
where: { AND: [{ event_type: { equals: $eventType } }, { start_age: { less_than: 10 } }] }
) {
docs {
information {
start_age
end_age
}
}
}
}You have two options:
1) Remove the name on your tab
name: 'information',this is grouping your data making your query incorrect.
2) Update your
whereto target the nested
event_type. I believe this should work:
where: { AND: [{ information__event_type: { equals: $eventType } }, { start_age: { less_than: 10 } }] }If that isn't right, go into your graphql explorer and find the correct field name for the nested information__event_type.
Star
Discord
online
Get dedicated engineering support directly from the Payload team.