mirror of
https://github.com/graphql-python/graphene-django.git
synced 2025-07-10 16:22:20 +03:00
feat: log exception by default
This commit is contained in:
parent
a78114ada3
commit
cbdc7e9786
|
@ -1,6 +1,7 @@
|
||||||
import inspect
|
import inspect
|
||||||
import json
|
import json
|
||||||
import re
|
import re
|
||||||
|
from traceback import print_tb
|
||||||
|
|
||||||
from django.db import connection, transaction
|
from django.db import connection, transaction
|
||||||
from django.http import HttpResponse, HttpResponseNotAllowed
|
from django.http import HttpResponse, HttpResponseNotAllowed
|
||||||
|
@ -53,6 +54,20 @@ def instantiate_middleware(middlewares):
|
||||||
yield middleware
|
yield middleware
|
||||||
|
|
||||||
|
|
||||||
|
class ExceptionLoggingExecutionContext(ExecutionContext):
|
||||||
|
|
||||||
|
"""An execution context which logs exceptions."""
|
||||||
|
|
||||||
|
def handle_field_error(
|
||||||
|
self,
|
||||||
|
error: GraphQLError,
|
||||||
|
return_type,
|
||||||
|
) -> None:
|
||||||
|
|
||||||
|
print_tb(error.original_error.__traceback__)
|
||||||
|
return super().handle_field_error(error, return_type)
|
||||||
|
|
||||||
|
|
||||||
class GraphQLView(View):
|
class GraphQLView(View):
|
||||||
graphiql_template = "graphene/graphiql.html"
|
graphiql_template = "graphene/graphiql.html"
|
||||||
|
|
||||||
|
@ -94,7 +109,7 @@ class GraphQLView(View):
|
||||||
pretty=False,
|
pretty=False,
|
||||||
batch=False,
|
batch=False,
|
||||||
subscription_path=None,
|
subscription_path=None,
|
||||||
execution_context_class=None,
|
execution_context_class=ExceptionLoggingExecutionContext,
|
||||||
):
|
):
|
||||||
if not schema:
|
if not schema:
|
||||||
schema = graphene_settings.SCHEMA
|
schema = graphene_settings.SCHEMA
|
||||||
|
|
Loading…
Reference in New Issue
Block a user