1
1
from contextlib import contextmanager
2
+
2
3
from django .db import connections
3
4
4
- from ....plugins import Plugin
5
- from ....core .schema import Schema
6
5
from ....core .types import Field
6
+ from ....plugins import Plugin
7
7
from .sql .tracking import unwrap_cursor , wrap_cursor
8
8
from .sql .types import DjangoDebugSQL
9
9
from .types import DjangoDebug
@@ -44,9 +44,10 @@ def debug_objecttype(objecttype):
44
44
45
45
46
46
class DjangoDebugPlugin (Plugin ):
47
+
47
48
def transform_type (self , _type ):
48
49
if _type == self .schema .query :
49
- return debug_objecttype ( _type )
50
+ return
50
51
return _type
51
52
52
53
def enable_instrumentation (self , wrapped_root ):
@@ -58,9 +59,19 @@ def disable_instrumentation(self):
58
59
for connection in connections .all ():
59
60
unwrap_cursor (connection )
60
61
62
+ def wrap_schema (self , schema_type ):
63
+ query = schema_type ._query
64
+ if query :
65
+ class_type = self .schema .objecttype (schema_type ._query )
66
+ assert class_type , 'The query in schema is not constructed with graphene'
67
+ _type = debug_objecttype (class_type )
68
+ schema_type ._query = self .schema .T (_type )
69
+ return schema_type
70
+
61
71
@contextmanager
62
72
def context_execution (self , executor ):
63
73
executor ['root' ] = WrappedRoot (root = executor ['root' ])
74
+ executor ['schema' ] = self .wrap_schema (executor ['schema' ])
64
75
self .enable_instrumentation (executor ['root' ])
65
76
yield executor
66
77
self .disable_instrumentation ()
0 commit comments