graphql-python / graphql-python/graphene

Depth limit validator key error if fragment undefined

Open
#1,538 0 comments 1 reaction 0 assignees View on GitHub
🐛 bug
Dominant language
Python
Stars
8.2k
Forks
818
PR merge metrics
No merged PRs in 30d

Description

**Current behaviour:**
When using the `depth_limit_validator` ([docs](https://docs.graphene-python.org/en/latest/execution/queryvalidation/#usage)), an invalid query can lead to a `KeyError` being thrown (from [here](https://github.com/graphql-python/graphene/blob/master/graphene/validation/depth_limit.py#L148)), which usually results in the API returning a 500 server error.

To reproduce:
- Add the `depth_limit_validator` to the `validation_rules` in your `GraphQLView`.
- Execute a query with an undefined fragment, i.e. something like:
```
query {
validQuery {
validField
...undefinedFragment
}
}
```

**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:**
- Version: 3.3
- Platform: n/a

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.