Skip to content

Commit 0d8f9db

Browse files
committed
Pass options from the fragment, not the template context
1 parent 3755850 commit 0d8f9db

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

graphene_django/templates/graphene/graphiql.html

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -100,22 +100,27 @@
100100
function updateURL() {
101101
history.replaceState(null, null, locationQuery(parameters));
102102
}
103-
// Render <GraphiQL /> into the body.
104-
ReactDOM.render(
105-
React.createElement(GraphiQL, {
106-
fetcher: graphQLFetcher,
103+
// If there are any fragment parameters, confirm the user wants to use them.
104+
if (Object.keys(parameters).length
105+
&& !window.confirm("An untrusted query has been loaded, continue loading query?")) {
106+
parameters = {};
107+
}
108+
var options = {
109+
fetcher: graphQLFetcher,
107110
onEditQuery: onEditQuery,
108111
onEditVariables: onEditVariables,
109112
onEditOperationName: onEditOperationName,
110-
query: '{{ query|escapejs }}',
111-
response: '{{ result|escapejs }}',
112-
{% if variables %}
113-
variables: '{{ variables|escapejs }}',
114-
{% endif %}
115-
{% if operation_name %}
116-
operationName: '{{ operation_name|escapejs }}',
117-
{% endif %}
118-
}),
113+
query: parameters.query,
114+
}
115+
if (parameters.variables) {
116+
options.variables = parameters.variables;
117+
}
118+
if (parameters.operation_name) {
119+
options.operationName = parameters.operation_name;
120+
}
121+
// Render <GraphiQL /> into the body.
122+
ReactDOM.render(
123+
React.createElement(GraphiQL, options),
119124
document.body
120125
);
121126
</script>

0 commit comments

Comments
 (0)