Skip to content

Commit d1b734f

Browse files
committed
Allow the user to see the query before prompting
This also allows the introspection query through so that the user can edit with intellisense before being prompted.
1 parent 9a5b355 commit d1b734f

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

graphene_django/templates/graphene/graphiql.html

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,31 @@
5858
otherParams[k] = parameters[k];
5959
}
6060
}
61+
62+
// If there are any fragment parameters, confirm the user wants to use them.
63+
var isReload = window.performance ? performance.navigation.type === 1 : false;
64+
var isQueryTrusted = Object.keys(parameters).length === 0 || isReload;
65+
6166
var fetchURL = locationQuery(otherParams);
67+
6268
// Defines a GraphQL fetcher using the fetch API.
6369
function graphQLFetcher(graphQLParams) {
70+
var isIntrospectionQuery = (
71+
graphQLParams.query !== parameters.query
72+
&& graphQLParams.query.indexOf('IntrospectionQuery') !== -1
73+
);
74+
75+
if (!isQueryTrusted
76+
&& !isIntrospectionQuery
77+
&& !window.confirm("This query was loaded from a link, are you sure you want to execute it?")) {
78+
return Promise.resolve('Aborting query.');
79+
}
80+
81+
// We don't want to set this for the introspection query
82+
if (!isIntrospectionQuery) {
83+
isQueryTrusted = true;
84+
}
85+
6486
var headers = {
6587
'Accept': 'application/json',
6688
'Content-Type': 'application/json'
@@ -100,13 +122,6 @@
100122
function updateURL() {
101123
history.replaceState(null, null, locationQuery(parameters));
102124
}
103-
// If there are any fragment parameters, confirm the user wants to use them.
104-
var isReload = window.performance ? performance.navigation.type === 1 : false;
105-
if (Object.keys(parameters).length
106-
&& !isReload
107-
&& !window.confirm("An untrusted query has been loaded, continue loading query?")) {
108-
parameters = {};
109-
}
110125
var options = {
111126
fetcher: graphQLFetcher,
112127
onEditQuery: onEditQuery,

0 commit comments

Comments
 (0)