graphql-python / graphql-python/flask-graphql

How to get GraphQL error objects using GraphQLView in 2.0.0?

未关闭
#61 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Python
星标
1.3k
派生
139
PR 合并指标
30 天内没有已合并 PR

描述

Hello,

We are using this library to add graphql support to our flask app. We used to have version 1.3.1 installed and the following view code was working correctly:

```
class AppGraphQLView(GraphQLView):
def execute_graphql_request(self, *args, **kwargs):
"""Extract any exceptions and send them to Raygun"""
result = super().execute_graphql_request(*args, **kwargs)

if result is not None and result.errors:
send_errors_to_raygun(result.errors)

return result
```

We've recently updated to version 2.0.0 of this library, and this caused our errors to not be sent to raygun, because our function is no longer called.. I discovered that the whole of GraphQLView has been refactored to not include `execute_graphql_request` anymore so I tried using `dispatch_request` instead.

However, `dispatch_request` returns a json object and any errors have only the message, no stacktrace or any other important information we would need to send to raygun.

I have tried to replicate this functionality without overwriting GraphQLView's implementation of `execute_graphql_request`, by using middleware instead:
```
def error_reporting_middleware(next, root, info, **kwargs):

result = next(root, info, **kwargs)

if result.is_rejected:
send_errors_to_raygun([result.reason])

return result
```
This kinda works, but I was wondering if there is a similar way to do it using the refactored GraphQLView in v2.0.0.

Thanks!

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。