Strapi graphql OR operator for where clause

I am working on a project using the strapi-plugin-graphql package.

I am trying to set up a query that filters on multiple fields, using the where parameter. If I pass multiple props into the where clause, I get results that only match to both queries.

query SearchThings($searchString: String!) {
  thing(where: { name_contains: $searchString, category: { name: $searchString }}) {
    ...Content
  }
}

Is there an out of the box way to implement this as an OR so matches to either of the conditions are returned? Or would this require writing a custom resolver?

Normally I would suggest using the complex query option but in the process of testing this I discovered a bug:

https://github.com/strapi/strapi/issues/8322

Thanks @DMehaffy for the quick response on this!

I’ve been following the github issue, and if I’m reading correctly, the fix was merged and deployed in version 3.2.4.

I’ve upgraded to 3.2.5, but I’m still getting results only when keyword matches all filter params.

entity(where: { _or: { name_contains: $searchKeyword }, fk_category: { name: $searchKeyword } }) {
  ...Fragment
}

Been following the other related threads, so I know there may be some bigger scope of work going on here. Just wanted to give an update.

Thanks!

actually, I dunno if it’s totally related now to GraphQL.

I replaced these GraphQL queries with conventional rest endpoints, and I am still getting the same error as I was with Apollo.

I am trying examples from this complex queries documentation but both the implicit and the explicit OR syntax also return only filters that match to all query params (implicit AND).

implicit OR syntax

`${API_URL}/?name_contains=${searchKeyword}&fk_catgory.name=${searchKeyword}``

works just fine with either of these individual queries by themselves.

explicit OR syntax

const query = qs.stringify({ 
  _where: { _or: [{ name_contains: searchKeyword }, { fk_catgory: { name: searchKeyword } }] } 
});

I am trying to do a combination of deep and complex filtering with the graphql plugin. I can get one or the other to work but not both. In the docs on the content API page and complex queries section there is a subsection “Combining AND and OR operators” that suggests this very thing is possible but when I try to run a query that is like the example shown (with an implicit AND) it returns the graphQLError - “Your filters contain a field ‘0.field1’ that doesn’t appear on your model definition nor it’s relations”

query QueryName($id:ID!,$id2:ID!,$id3!) {
memories(where:{
_or:[
{creator:$id},
[{field1_in:$id2},{field2:$id3},{visibility:“group”}]
]}) {
fieldA
fieldB
field…
}
}

if try updating the query to use an explicit AND (shown below) I get this graphQLError - “Your filters contain a field ‘_and’ that doesn’t appear on your model definition nor it’s relations”

query QueryName($id:ID!,$id2:ID!,$id3!) {
memories(where:{
_or:[
{creator:$id},
{_and:[{field1_in:$id2},{field2:$id3},{visibility:“group”}]}
]}) {
fieldA
fieldB
field…
}
}

Lastly, for the purposes of testing I tried to simplify the query and just do a single complex filter (shown below) and this query works.

query QueryName($id:ID!) {
memories(where:{
_or:[
{creator:$id},
{visibility:“group”}
]}) {
fieldA
fieldB
field…
}
}

Is it possible to nest complex queries like this using the graphql plugin or should I find another way of doing this? The docs defintely suggest it is possible but the example they show in the above mentioned docs section is using the REST API.

I found the solution to my problem. The formatting of the implicit AND (the second part of my OR quoted below) needed to be tweaked a little bit

Here is the correct formatting for that line. Once I changed just that line everything worked as expected

{field1_in:$id2,field2:$id3,visibility:“group”}