Use of logical operators in GraphQL query

System Information
  • Strapi Version: 4.5.0
  • Operating System: Mac OS
  • Database: SQLite3
  • Node Version: 18.12.0
  • NPM Version: 8.19.2

I’m trying to do a complex filter (e.g. get movies which are produced between several decades and which have a multiple duration span) which involves combining logical operators and other operators.

The following doesn’t work since I can only have one “or” input field :

query Movies ($sort: [String]){
  movies(sort: $sort, pagination: {limit: 100}, filters: {
        or: [
          { year: { between: [1960,1969] }},
          { year: { between: [1970,1979] }}
          ],
        or: [
          { duration: { between: ["00:05:00.000", "00:20:00.000"] }},
          { duration: { gt: "00:20:00.000" }}
        ]
  }) {}
}

The following doesn’t work as the “or” does not allow complex nested operators :

query Movies ($sort: [String]){
  movies(sort: $sort, pagination: {limit: 100}, filters: {
       duration: {
         or: [
           { between: ["00:05:00.000", "00:20:00.000"] },
           { gt: "00:20:00.000" }
         ]
       },
       year: {
         or: [
           { between: [1960,1969] },
           { between: [1970,1979] }
         ]
       }
  }) {}
}

Am I missing something in my syntax or is this impossible and would I have to write a custom resolver for this type of filtering ?

You can do an $and:[{$or:1},{$or:2}]

1 Like