mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-13 13:16:49 +03:00
Improved debug plugin structure
This commit is contained in:
parent
bd35fcee6c
commit
dd5b26e6ed
|
@ -1,9 +1,9 @@
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
|
|
||||||
from django.db import connections
|
from django.db import connections
|
||||||
|
|
||||||
from ....plugins import Plugin
|
|
||||||
from ....core.schema import Schema
|
|
||||||
from ....core.types import Field
|
from ....core.types import Field
|
||||||
|
from ....plugins import Plugin
|
||||||
from .sql.tracking import unwrap_cursor, wrap_cursor
|
from .sql.tracking import unwrap_cursor, wrap_cursor
|
||||||
from .sql.types import DjangoDebugSQL
|
from .sql.types import DjangoDebugSQL
|
||||||
from .types import DjangoDebug
|
from .types import DjangoDebug
|
||||||
|
@ -44,9 +44,10 @@ def debug_objecttype(objecttype):
|
||||||
|
|
||||||
|
|
||||||
class DjangoDebugPlugin(Plugin):
|
class DjangoDebugPlugin(Plugin):
|
||||||
|
|
||||||
def transform_type(self, _type):
|
def transform_type(self, _type):
|
||||||
if _type == self.schema.query:
|
if _type == self.schema.query:
|
||||||
return debug_objecttype(_type)
|
return
|
||||||
return _type
|
return _type
|
||||||
|
|
||||||
def enable_instrumentation(self, wrapped_root):
|
def enable_instrumentation(self, wrapped_root):
|
||||||
|
@ -58,9 +59,19 @@ class DjangoDebugPlugin(Plugin):
|
||||||
for connection in connections.all():
|
for connection in connections.all():
|
||||||
unwrap_cursor(connection)
|
unwrap_cursor(connection)
|
||||||
|
|
||||||
|
def wrap_schema(self, schema_type):
|
||||||
|
query = schema_type._query
|
||||||
|
if query:
|
||||||
|
class_type = self.schema.objecttype(schema_type._query)
|
||||||
|
assert class_type, 'The query in schema is not constructed with graphene'
|
||||||
|
_type = debug_objecttype(class_type)
|
||||||
|
schema_type._query = self.schema.T(_type)
|
||||||
|
return schema_type
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def context_execution(self, executor):
|
def context_execution(self, executor):
|
||||||
executor['root'] = WrappedRoot(root=executor['root'])
|
executor['root'] = WrappedRoot(root=executor['root'])
|
||||||
|
executor['schema'] = self.wrap_schema(executor['schema'])
|
||||||
self.enable_instrumentation(executor['root'])
|
self.enable_instrumentation(executor['root'])
|
||||||
yield executor
|
yield executor
|
||||||
self.disable_instrumentation()
|
self.disable_instrumentation()
|
||||||
|
|
|
@ -131,6 +131,8 @@ class Schema(object):
|
||||||
executor = kwargs
|
executor = kwargs
|
||||||
executor['root'] = root
|
executor['root'] = root
|
||||||
executor['args'] = args
|
executor['args'] = args
|
||||||
|
executor['schema'] = self.schema
|
||||||
|
executor['request'] = request
|
||||||
contexts = []
|
contexts = []
|
||||||
for plugin in self.plugins:
|
for plugin in self.plugins:
|
||||||
if not hasattr(plugin, 'context_execution'):
|
if not hasattr(plugin, 'context_execution'):
|
||||||
|
@ -139,8 +141,6 @@ class Schema(object):
|
||||||
executor = context.__enter__()
|
executor = context.__enter__()
|
||||||
contexts.append((context, executor))
|
contexts.append((context, executor))
|
||||||
result = self.executor.execute(
|
result = self.executor.execute(
|
||||||
self.schema,
|
|
||||||
request,
|
|
||||||
**executor
|
**executor
|
||||||
)
|
)
|
||||||
for context, value in contexts[::-1]:
|
for context, value in contexts[::-1]:
|
||||||
|
|
|
@ -129,6 +129,7 @@ class MountedType(FieldType, ArgumentType):
|
||||||
|
|
||||||
|
|
||||||
class NamedType(InstanceType):
|
class NamedType(InstanceType):
|
||||||
|
|
||||||
def __init__(self, name=None, default_name=None, *args, **kwargs):
|
def __init__(self, name=None, default_name=None, *args, **kwargs):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.default_name = None
|
self.default_name = None
|
||||||
|
|
Loading…
Reference in New Issue
Block a user