We could add a configurable query depth limit during the validation phase of execution.
This would be a simple way to mitigate a bit of risk when your schema contains recursive fields.
__Example schema__
type Query {
characters: [Character]!
}
type Character {
id: ID!
name: String!
friends: [Character]!
}
__Query__
query TooDeep { # depth = 0
characters { # depth = 1
id # depth = 2
name # depth = 2
friends { # depth = 2
friends { # depth = 3
friends { # depth = 4
friends { # depth = 5
friends { # depth = 6
id # depth = 7
name # depth = 7
}
}
}
}
}
}
}
A functional option passed at schema initialization should work pretty well for this.
// Schema represents a GraphQL schema with an optional resolver.
type Schema struct {
schema *schema.Schema
res *resolvable.Schema
+ maxDepth int
maxParallelism int
tracer trace.Tracer
logger log.Logger
}
+ func MaxDepth(n int) SchemaOpt {
+ return func(s *Schema) {
+ s.maxDepth = n
+ }
+ }
Thoughts? Good idea? Unnecessary?
I'm going to take a look at this.
@tonyghita
can you please close this issue as it was fixed by #190? Thanks!
Closing, fixed by #190
Most helpful comment
I'm going to take a look at this.