mirror of
https://github.com/graphql-python/graphene-django.git
synced 2024-11-22 01:27:01 +03:00
fix: fix graphiql request failure
This commit is contained in:
parent
a8ceca77ed
commit
95a0642818
|
@ -60,40 +60,27 @@
|
||||||
|
|
||||||
function trueLambda() { return true; };
|
function trueLambda() { return true; };
|
||||||
|
|
||||||
var fetcher = GraphiQL.createFetcher({
|
var headers = {};
|
||||||
|
var cookies = ("; " + document.cookie).split("; csrftoken=");
|
||||||
|
if (cookies.length == 2) {
|
||||||
|
csrftoken = cookies.pop().split(";").shift();
|
||||||
|
} else {
|
||||||
|
csrftoken = document.querySelector("[name=csrfmiddlewaretoken]").value;
|
||||||
|
}
|
||||||
|
if (csrftoken) {
|
||||||
|
headers['X-CSRFToken'] = csrftoken
|
||||||
|
}
|
||||||
|
|
||||||
|
var graphQLFetcher = GraphiQL.createFetcher({
|
||||||
url: fetchURL,
|
url: fetchURL,
|
||||||
wsClient: graphqlWs.createClient({
|
wsClient: graphqlWs.createClient({
|
||||||
url: subscribeURL,
|
url: subscribeURL,
|
||||||
shouldRetry: trueLambda,
|
shouldRetry: trueLambda,
|
||||||
lazy: true,
|
lazy: true,
|
||||||
})
|
}),
|
||||||
|
headers: headers
|
||||||
})
|
})
|
||||||
|
|
||||||
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=");
|
|
||||||
if (cookies.length == 2) {
|
|
||||||
csrftoken = cookies.pop().split(";").shift();
|
|
||||||
} else {
|
|
||||||
csrftoken = document.querySelector("[name=csrfmiddlewaretoken]").value;
|
|
||||||
}
|
|
||||||
if (csrftoken) {
|
|
||||||
headers['X-CSRFToken'] = csrftoken
|
|
||||||
}
|
|
||||||
|
|
||||||
opts.headers = headers
|
|
||||||
|
|
||||||
return fetcher(graphQLParams, opts)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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.
|
||||||
function onEditQuery(newQuery) {
|
function onEditQuery(newQuery) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user