5
5
from graphene .contrib .django .utils import DJANGO_FILTER_INSTALLED
6
6
7
7
from ...tests .models import Reporter
8
- from ..plugin import DjangoDebugPlugin
8
+ from ..middleware import DjangoDebugMiddleware
9
+ from ..types import DjangoDebug
10
+
11
+
12
+ class context (object ):
13
+ pass
9
14
10
15
# from examples.starwars_django.models import Character
11
16
@@ -25,6 +30,7 @@ class Meta:
25
30
26
31
class Query (graphene .ObjectType ):
27
32
reporter = graphene .Field (ReporterType )
33
+ debug = graphene .Field (DjangoDebug , name = '__debug' )
28
34
29
35
def resolve_reporter (self , * args , ** kwargs ):
30
36
return Reporter .objects .first ()
@@ -51,8 +57,8 @@ def resolve_reporter(self, *args, **kwargs):
51
57
}]
52
58
}
53
59
}
54
- schema = graphene .Schema (query = Query , plugins = [ DjangoDebugPlugin ()])
55
- result = schema .execute (query )
60
+ schema = graphene .Schema (query = Query , middlewares = [ DjangoDebugMiddleware ()])
61
+ result = schema .execute (query , context_value = context () )
56
62
assert not result .errors
57
63
assert result .data == expected
58
64
@@ -70,6 +76,7 @@ class Meta:
70
76
71
77
class Query (graphene .ObjectType ):
72
78
all_reporters = ReporterType .List ()
79
+ debug = graphene .Field (DjangoDebug , name = '__debug' )
73
80
74
81
def resolve_all_reporters (self , * args , ** kwargs ):
75
82
return Reporter .objects .all ()
@@ -98,8 +105,8 @@ def resolve_all_reporters(self, *args, **kwargs):
98
105
}]
99
106
}
100
107
}
101
- schema = graphene .Schema (query = Query , plugins = [ DjangoDebugPlugin ()])
102
- result = schema .execute (query )
108
+ schema = graphene .Schema (query = Query , middlewares = [ DjangoDebugMiddleware ()])
109
+ result = schema .execute (query , context_value = context () )
103
110
assert not result .errors
104
111
assert result .data == expected
105
112
@@ -117,6 +124,7 @@ class Meta:
117
124
118
125
class Query (graphene .ObjectType ):
119
126
all_reporters = DjangoConnectionField (ReporterType )
127
+ debug = graphene .Field (DjangoDebug , name = '__debug' )
120
128
121
129
def resolve_all_reporters (self , * args , ** kwargs ):
122
130
return Reporter .objects .all ()
@@ -146,8 +154,8 @@ def resolve_all_reporters(self, *args, **kwargs):
146
154
}]
147
155
},
148
156
}
149
- schema = graphene .Schema (query = Query , plugins = [ DjangoDebugPlugin ()])
150
- result = schema .execute (query )
157
+ schema = graphene .Schema (query = Query , middlewares = [ DjangoDebugMiddleware ()])
158
+ result = schema .execute (query , context_value = context () )
151
159
assert not result .errors
152
160
assert result .data ['allReporters' ] == expected ['allReporters' ]
153
161
assert 'COUNT' in result .data ['__debug' ]['sql' ][0 ]['rawSql' ]
@@ -172,6 +180,7 @@ class Meta:
172
180
173
181
class Query (graphene .ObjectType ):
174
182
all_reporters = DjangoFilterConnectionField (ReporterType )
183
+ debug = graphene .Field (DjangoDebug , name = '__debug' )
175
184
176
185
def resolve_all_reporters (self , * args , ** kwargs ):
177
186
return Reporter .objects .all ()
@@ -201,8 +210,8 @@ def resolve_all_reporters(self, *args, **kwargs):
201
210
}]
202
211
},
203
212
}
204
- schema = graphene .Schema (query = Query , plugins = [ DjangoDebugPlugin ()])
205
- result = schema .execute (query )
213
+ schema = graphene .Schema (query = Query , middlewares = [ DjangoDebugMiddleware ()])
214
+ result = schema .execute (query , context_value = context () )
206
215
assert not result .errors
207
216
assert result .data ['allReporters' ] == expected ['allReporters' ]
208
217
assert 'COUNT' in result .data ['__debug' ]['sql' ][0 ]['rawSql' ]
0 commit comments