Skip to content

Commit dd5b26e

Browse files
committed
Improved debug plugin structure
1 parent bd35fce commit dd5b26e

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

graphene/contrib/django/debug/plugin.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from contextlib import contextmanager
2+
23
from django.db import connections
34

4-
from ....plugins import Plugin
5-
from ....core.schema import Schema
65
from ....core.types import Field
6+
from ....plugins import Plugin
77
from .sql.tracking import unwrap_cursor, wrap_cursor
88
from .sql.types import DjangoDebugSQL
99
from .types import DjangoDebug
@@ -44,9 +44,10 @@ def debug_objecttype(objecttype):
4444

4545

4646
class DjangoDebugPlugin(Plugin):
47+
4748
def transform_type(self, _type):
4849
if _type == self.schema.query:
49-
return debug_objecttype(_type)
50+
return
5051
return _type
5152

5253
def enable_instrumentation(self, wrapped_root):
@@ -58,9 +59,19 @@ def disable_instrumentation(self):
5859
for connection in connections.all():
5960
unwrap_cursor(connection)
6061

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+
6171
@contextmanager
6272
def context_execution(self, executor):
6373
executor['root'] = WrappedRoot(root=executor['root'])
74+
executor['schema'] = self.wrap_schema(executor['schema'])
6475
self.enable_instrumentation(executor['root'])
6576
yield executor
6677
self.disable_instrumentation()

graphene/core/schema.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ def execute(self, request='', root=None, args=None, **kwargs):
131131
executor = kwargs
132132
executor['root'] = root
133133
executor['args'] = args
134+
executor['schema'] = self.schema
135+
executor['request'] = request
134136
contexts = []
135137
for plugin in self.plugins:
136138
if not hasattr(plugin, 'context_execution'):
@@ -139,8 +141,6 @@ def execute(self, request='', root=None, args=None, **kwargs):
139141
executor = context.__enter__()
140142
contexts.append((context, executor))
141143
result = self.executor.execute(
142-
self.schema,
143-
request,
144144
**executor
145145
)
146146
for context, value in contexts[::-1]:

graphene/core/types/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ class MountedType(FieldType, ArgumentType):
129129

130130

131131
class NamedType(InstanceType):
132+
132133
def __init__(self, name=None, default_name=None, *args, **kwargs):
133134
self.name = name
134135
self.default_name = None

0 commit comments

Comments
 (0)