Intertwined nested filter

I know Nested Filter is a though and reoccuring topic somehow, but please hear me out.

Lets imagine a schema like this: (see more info in #12556)

schema
type Student {
    id: String! @id
    age: DateTime @search
    firstName: String! @search(by: [term])
    classes: [Class!] @hasInverse(field: students)
}

type Class {
    id: String! @id
    description: String! @search(by: [term])
    students: [Student!]!
    room: Room!
}

type Room {
    id: String! @id
    name: String! @search(by: [term])
    classes: [Class!] @hasInverse(field: room)
}

A normal use case (at least in sql) would be to get all students that have Math in Room 501 and/or English in 502.

pseudo sql query
SELECT * FROM student
	JOIN class ON student.class_id = class.id
	JOIN room ON class.room_id = room.id
	WHERE (class.description = 'Math' AND room.name = '501') OR 
		(class.description = 'English' AND room.name = '502')

Is there a way to realize this in dgraph graphql, I am not aware of?
I know I could use a mix of @cascade and filter, which works fine for single values, but the intertwined where clause would make problems as each filter is interpreted seperately.

most useful graphql query to my best knowledge
query test(
  $filterStudent: StudentFilter,
  $filterClass: ClassFilter,
  $filterRoom: RoomFilter,
) {
  queryStudent(filter: $filterStudent) @cascade(fields: ['classes']){
     id
     age
     firstName
     classes(filter: $filterClass) @cascade(fields: ['room']) {
       id
       description
       room(filter: $filterRoom) {
         id
         name
      }
    }
  }
}

Hi @jlnrrg,

Yes, this seems like a legit use case for supporting nested filters .

We will be looking into adding support for it.

Current work around could be to have a roomName: String! @search(by: [hash]) field inside type Class. This may store number of the Room. (501, 502 etc.)

If this field is added, the query to find such students could be rewritten as:

query {
  queryClass(filter:{or:[{and:[{description:{anyofterms:"Math"}}, {roomName:{eq:"501"}}]},
                          {and:[{description:{anyofterms:"English"}}, {roomName:{eq:"502"}}]}]}){
    students{
      firstName
      ...
    }
  }
}

I am assuming in above query that description field contains name of the class.

The other possible workaround which should work around with current schema is as follows:

  1. Fetch all students taking Math class in Room 501 using
queryRoom(filter: \* Apply filter where room name is 501*\) {
    classes(filter: \* Apply filter where class description is Math*\) {
        students{
        ...
       }
    }
}
  1. Similarly fetch all students taking English in Room 502.
  2. Combine the results and perform union or intersection on student list at the client side.