Graphql-go: Feature request: configurable query depth limit

Created on 16 Oct 2017  路  3Comments  路  Source: graph-gophers/graphql-go

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?

Most helpful comment

I'm going to take a look at this.

All 3 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rogchap picture rogchap  路  5Comments

bsr203 picture bsr203  路  6Comments

bsr203 picture bsr203  路  7Comments

JitinGuglani picture JitinGuglani  路  6Comments

jakubdal picture jakubdal  路  6Comments