fix: fix graphiql request failure

This commit is contained in:
Kien Dang 2023-05-03 04:24:32 +08:00 committed by Firas K
parent a8ceca77ed
commit 95a0642818

View File

@ -60,25 +60,7 @@
function trueLambda() { return true; }; function trueLambda() { return true; };
var fetcher = GraphiQL.createFetcher({ var headers = {};
url: fetchURL,
wsClient: graphqlWs.createClient({
url: subscribeURL,
shouldRetry: trueLambda,
lazy: true,
})
})
function graphQLFetcher(graphQLParams, opts) {
if (typeof opts === 'undefined') {
opts = {};
}
var headers = opts.headers || {};
headers['Accept'] = headers['Accept'] || 'application/json';
headers['Content-Type'] = headers['Content-Type'] || 'application/json';
// Parse the cookie value for a CSRF token
var csrftoken;
var cookies = ("; " + document.cookie).split("; csrftoken="); var cookies = ("; " + document.cookie).split("; csrftoken=");
if (cookies.length == 2) { if (cookies.length == 2) {
csrftoken = cookies.pop().split(";").shift(); csrftoken = cookies.pop().split(";").shift();
@ -89,10 +71,15 @@
headers['X-CSRFToken'] = csrftoken headers['X-CSRFToken'] = csrftoken
} }
opts.headers = headers var graphQLFetcher = GraphiQL.createFetcher({
url: fetchURL,
return fetcher(graphQLParams, opts) wsClient: graphqlWs.createClient({
} url: subscribeURL,
shouldRetry: trueLambda,
lazy: true,
}),
headers: headers
})
// When the query and variables string is edited, update the URL bar so // When the query and variables string is edited, update the URL bar so
// that it can be easily shared. // that it can be easily shared.