File tree Expand file tree Collapse file tree 3 files changed +28
-4
lines changed Expand file tree Collapse file tree 3 files changed +28
-4
lines changed Original file line number Diff line number Diff line change @@ -245,7 +245,11 @@ def render_graphql_ide(
245
245
self , request : HttpRequest , request_data : GraphQLRequestData
246
246
) -> HttpResponse :
247
247
try :
248
- content = render_to_string ("graphql/graphiql.html" , request = request )
248
+ content = render_to_string (
249
+ "graphql/graphiql.html" ,
250
+ request = request ,
251
+ context = request_data .to_template_context (),
252
+ )
249
253
except TemplateDoesNotExist :
250
254
content = self .graphql_ide_html
251
255
@@ -307,7 +311,11 @@ async def render_graphql_ide(
307
311
self , request : HttpRequest , request_data : GraphQLRequestData
308
312
) -> HttpResponse :
309
313
try :
310
- content = render_to_string ("graphql/graphiql.html" , request = request )
314
+ content = render_to_string (
315
+ "graphql/graphiql.html" ,
316
+ request = request ,
317
+ context = request_data .to_template_context (),
318
+ )
311
319
except TemplateDoesNotExist :
312
320
content = self .graphql_ide_html
313
321
Original file line number Diff line number Diff line change @@ -133,7 +133,14 @@ def dispatch_request(self) -> ResponseReturnValue:
133
133
def render_graphql_ide (
134
134
self , request : Request , request_data : GraphQLRequestData
135
135
) -> Response :
136
- return render_template_string (self .graphql_ide_html ) # type: ignore
136
+ return render_template_string (
137
+ self .graphql_ide_html ,
138
+ ** {
139
+ "query" : request_data .query ,
140
+ "variables" : request_data .variables ,
141
+ "operationName" : request_data .operation_name ,
142
+ },
143
+ ) # type: ignore
137
144
138
145
139
146
class AsyncFlaskHTTPRequestAdapter (AsyncHTTPRequestAdapter ):
@@ -198,7 +205,9 @@ async def dispatch_request(self) -> ResponseReturnValue: # type: ignore
198
205
async def render_graphql_ide (
199
206
self , request : Request , request_data : GraphQLRequestData
200
207
) -> Response :
201
- content = render_template_string (self .graphql_ide_html )
208
+ content = render_template_string (
209
+ self .graphql_ide_html , ** request_data .to_template_context ()
210
+ )
202
211
return Response (content , status = 200 , content_type = "text/html" )
203
212
204
213
def is_websocket_request (self , request : Request ) -> TypeGuard [Request ]:
Original file line number Diff line number Diff line change @@ -37,6 +37,13 @@ class GraphQLRequestData:
37
37
extensions : Optional [dict [str , Any ]]
38
38
protocol : Literal ["http" , "multipart-subscription" , "subscription" ] = "http"
39
39
40
+ def to_template_context (self ) -> dict [str , Any ]:
41
+ return {
42
+ "query" : self .query ,
43
+ "variables" : self .variables ,
44
+ "operationName" : self .operation_name ,
45
+ }
46
+
40
47
41
48
__all__ = [
42
49
"GraphQLHTTPResponse" ,
You can’t perform that action at this time.
0 commit comments