graphql-python / graphene

GraphQL framework for Python
http://graphene-python.org/
MIT License
8.1k stars 827 forks source link

Depth limit validator key error if fragment undefined #1538

Open ahmedaljawahiry opened 8 months ago

ahmedaljawahiry commented 8 months ago

Current behaviour: When using the depth_limit_validator (docs), an invalid query can lead to a KeyError being thrown (from here), which usually results in the API returning a 500 server error.

To reproduce:

Expected behaviour: A standard validation error response, like:

{
  "errors": [
    {
      "message": "Unknown fragment 'undefinedFragment'.",
      "locations": [
        {
          "line": x,
          "column": y
        }
      ]
    }
  ]
}

Since this is something that's caught by the standard validators, depth_limit_validator should probably just skip such errors. Or, do whatever the other validators do when they hit an "unrelated" error.

Environment: