I've been reading that it is important to secure your applications with the a Maximum Query Depth. Meaning, to limit the number of "levels" that the query has. Example of a very deep query:
query IAmEvil {
author(id: "abc") {
posts {
author {
posts {
author {
posts {
author {
# that could go on as deep as the client wants!
}
}
}
}
}
}
}
}
How can I know the level of depth of my query? and ultimately not allowed queries with more that a depth of 4 to perform. Can I get the full query to count the deepness manually? Or is their already an implementation?
This problem is also described here: https://www.howtographql.com/advanced/4-security/
You can write a middleware to check the selection_depth and block it. Something like that: