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
}
}
}
}