[GraphQL] Searching for *multiple* objects based on multiple conditions for each object

System Information
  • Strapi Version: v0.1.0
  • Operating System: Mac OS 11.1
  • Database: PostgreSQL
  • Node Version: v14.16.0
  • NPM Version: 6.14.11

So, I have a schema like so:

type School {
  id: ID!
  created_at: DateTime!
  updated_at: DateTime!
  name: String
  location: String
  link: String
  notes: String
  course_identifier: String
  postgraduate: Boolean
  published_at: DateTime
  grades(sort: String, limit: Int, start: Int, where: JSON): [Grades]
}

type Grades {
  id: ID!
  created_at: DateTime!
  updated_at: DateTime!
  letter: String
  number: Int
  school: School
  merits: Int
  distinctions: Int
  qualification: Qualifications
  published_at: DateTime
}


type Qualifications {
  id: ID!
  created_at: DateTime!
  updated_at: DateTime!
  name: String
  level: Int
  type: String
  published_at: DateTime
  grades(sort: String, limit: Int, start: Int, where: JSON): [Grades]
}

Schools belongs to many Grades, Grades belongs to one Qualifications.

I want the ability to search for schools based on grades and qualifications.

So in plain English: Find all schools that have the following provided: Grade that has letter with value of “A”, with a Qualification that has name with a value of “GCSE Science”, AND another Grade of letter “B”, that has a Qualification with a name that has a value of ‘GCSE English’

So basically, I want the ability to search based on grades and qualifications, and I want to make sure that if one of my qualifications provided doesn’t match the criteria, I want no results.

Right now this is the closest I have:

query{
    Schools(where:{_or:[{grades:{letter:"F", qualification:{name:"GCSE Science"}}}, {grades:{letter:"B", qualification:{name:"GCSE English"}}}]}) {
        name,
        grades {
            letter
            number
            merits
            qualification{
                name
                level
            }
        }
    }
}

But the problem is, because this uses _or, if I dont get the right grade for “GCSE Science” for instance, but the right grade for GCSE English, the school will still show up in the results, because the Science condition wont be met, but the English one will be.

What I want is, I want to return only the schools that contain the multiple grades I’ve specified.

Any help would be greatly appreciated!

I would suggest writing a custom controller for your graphql query. It is easier to fine-tune queries this way.