2929 <script src="//cdn.jsdelivr.net/npm/[email protected] /umd/react.production.min.js"></script> 3030 <script src="//cdn.jsdelivr.net/npm/[email protected] /umd/react-dom.production.min.js"></script> 3131 <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> 3234</head>
3335<body>
3436 <script>
6365 otherParams[k] = parameters[k];
6466 }
6567 }
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+
6682 var fetchURL = locationQuery(otherParams);
6783
6884 // Defines a GraphQL fetcher using the fetch API.
110126 // Render <GraphiQL /> into the body.
111127 ReactDOM.render(
112128 React.createElement(GraphiQL, {
113- fetcher: graphQLFetcher,
129+ fetcher: subscriptionsFetcher || graphQLFetcher,
114130 onEditQuery: onEditQuery,
115131 onEditVariables: onEditVariables,
116132 onEditOperationName: onEditOperationName,
@@ -149,7 +165,7 @@ def process_var(template, name, value, jsonify=False):
149165
150166
151167def simple_renderer (template , ** values ):
152- replace = ["graphiql_version" ]
168+ replace = ["graphiql_version" , "subscriptions" ]
153169 replace_jsonify = ["query" , "result" , "variables" , "operation_name" ]
154170
155171 for rep in replace :
@@ -167,6 +183,7 @@ async def render_graphiql(
167183 graphiql_template = None ,
168184 params = None ,
169185 result = None ,
186+ subscriptions = None ,
170187):
171188 graphiql_version = graphiql_version or GRAPHIQL_VERSION
172189 template = graphiql_template or TEMPLATE
@@ -176,6 +193,7 @@ async def render_graphiql(
176193 "variables" : params and params .variables ,
177194 "operation_name" : params and params .operation_name ,
178195 "result" : result ,
196+ "subscriptions" : subscriptions or "" ,
179197 }
180198
181199 if jinja_env :
0 commit comments