29
29
<script src="//cdn.jsdelivr.net/npm/[email protected] /umd/react.production.min.js"></script>
30
30
<script src="//cdn.jsdelivr.net/npm/[email protected] /umd/react-dom.production.min.js"></script>
31
31
<script src="//cdn.jsdelivr.net/npm/graphiql@{{graphiql_version}}/graphiql.min.js"></script>
32
+ <script src="//cdn.jsdelivr.net/npm/[email protected] /browser/client.js"></script>
33
+ <script src="//cdn.jsdelivr.net//npm/[email protected] /browser/client.js"></script>
32
34
</head>
33
35
<body>
34
36
<script>
63
65
otherParams[k] = parameters[k];
64
66
}
65
67
}
68
+
69
+ var subscriptionsFetcher;
70
+ if ('{{subscriptions}}') {
71
+ const subscriptionsClient = new SubscriptionsTransportWs.SubscriptionClient(
72
+ '{{ subscriptions }}',
73
+ {reconnect: true}
74
+ );
75
+
76
+ subscriptionsFetcher = GraphiQLSubscriptionsFetcher.graphQLFetcher(
77
+ subscriptionsClient,
78
+ graphQLFetcher
79
+ );
80
+ }
81
+
66
82
var fetchURL = locationQuery(otherParams);
67
83
68
84
// Defines a GraphQL fetcher using the fetch API.
110
126
// Render <GraphiQL /> into the body.
111
127
ReactDOM.render(
112
128
React.createElement(GraphiQL, {
113
- fetcher: graphQLFetcher,
129
+ fetcher: subscriptionsFetcher || graphQLFetcher,
114
130
onEditQuery: onEditQuery,
115
131
onEditVariables: onEditVariables,
116
132
onEditOperationName: onEditOperationName,
@@ -149,7 +165,7 @@ def process_var(template, name, value, jsonify=False):
149
165
150
166
151
167
def simple_renderer (template , ** values ):
152
- replace = ["graphiql_version" ]
168
+ replace = ["graphiql_version" , "subscriptions" ]
153
169
replace_jsonify = ["query" , "result" , "variables" , "operation_name" ]
154
170
155
171
for rep in replace :
@@ -167,6 +183,7 @@ async def render_graphiql(
167
183
graphiql_template = None ,
168
184
params = None ,
169
185
result = None ,
186
+ subscriptions = None ,
170
187
):
171
188
graphiql_version = graphiql_version or GRAPHIQL_VERSION
172
189
template = graphiql_template or TEMPLATE
@@ -176,6 +193,7 @@ async def render_graphiql(
176
193
"variables" : params and params .variables ,
177
194
"operation_name" : params and params .operation_name ,
178
195
"result" : result ,
196
+ "subscriptions" : subscriptions or "" ,
179
197
}
180
198
181
199
if jinja_env :
0 commit comments