How to query and filter more than one record/post type in a single query

I’m trying to query the GraphQL api to find any record of certain types that match a certain filter.

Two common example cases:
Case 1: Search by slug
I know the “slug” of a page/record, but I don’t know its modelType, how can I query the GraphQL api to find any record that has that slug? (this can happen if you have a “pages” record type, but you also have special unique pages record types, like landingPages, or aboutPage, or contactPage).

Case 2: Search by category
I have a Category, and Articles OR Projects could have that category. How could I search for any Article or Project that has Category X? Searching them separately isn’t a good option, because sorting and pagination would be thrown off. My expectations is something like the current Modular Content Fields, using ... on Project {}

Something like this would make sense:

Hello @maikueo welcome! :slight_smile:

Currently we don’t have the Meta fields option that you’ve linked.

What I would do in your case is something like this:

landings: allLandingPages(filter: { slug: { eq: "bike" } }) {
pages: allPages(filter: { slug: { eq: "bike" } }) {

and similarly on the category search, except you need to get the category ID first. We cannot do “deep filtering” right now and there’s a feature request for that. Please vote that or comment if you have more ideas.

Hi @mat_jack1!
Thank you. I think that would be helpful in some cases! :slight_smile:

For the Category search case though, having them split into two queries would mean that paginating and sorting wouldn’t really be possible.
And building a custom site search would also be hard without mixed type queries (I know there is the Site Search widget here which would probably work for a lot of cases, but if you want to make a search that shows more things like images or certain props, or a search that has more capabilities I guess it would need to be filtered by type first)

Great work on the CMS by the way :slight_smile: It is probably one of the friendliest UI’s and really the best suited to making websites I’ve seen so far.

I see what you are saying, yes, that meta option would be useful.

I’ve noted that down internally and we’ll discuss that on the next development iteration. Cannot say right now if we are going to pick that up. If you want to publicly track that you can open a feature request maybe