Pass options from the fragment, not the template context

This commit is contained in:
Dan Palmer 2018-08-30 19:48:21 +01:00
parent 3755850c2e
commit 0d8f9db3fb
No known key found for this signature in database
GPG Key ID: DD869B28A1B7AA92

View File

@ -100,22 +100,27 @@ add "&raw" to the end of the URL within a browser.
function updateURL() { function updateURL() {
history.replaceState(null, null, locationQuery(parameters)); history.replaceState(null, null, locationQuery(parameters));
} }
// Render <GraphiQL /> into the body. // If there are any fragment parameters, confirm the user wants to use them.
ReactDOM.render( if (Object.keys(parameters).length
React.createElement(GraphiQL, { && !window.confirm("An untrusted query has been loaded, continue loading query?")) {
fetcher: graphQLFetcher, parameters = {};
}
var options = {
fetcher: graphQLFetcher,
onEditQuery: onEditQuery, onEditQuery: onEditQuery,
onEditVariables: onEditVariables, onEditVariables: onEditVariables,
onEditOperationName: onEditOperationName, onEditOperationName: onEditOperationName,
query: '{{ query|escapejs }}', query: parameters.query,
response: '{{ result|escapejs }}', }
{% if variables %} if (parameters.variables) {
variables: '{{ variables|escapejs }}', options.variables = parameters.variables;
{% endif %} }
{% if operation_name %} if (parameters.operation_name) {
operationName: '{{ operation_name|escapejs }}', options.operationName = parameters.operation_name;
{% endif %} }
}), // Render <GraphiQL /> into the body.
ReactDOM.render(
React.createElement(GraphiQL, options),
document.body document.body
); );
</script> </script>