|
60 | 60 |
|
61 | 61 | function trueLambda() { return true; };
|
62 | 62 |
|
63 |
| - var fetcher = GraphiQL.createFetcher({ |
| 63 | + var headers = {}; |
| 64 | + var cookies = ("; " + document.cookie).split("; csrftoken="); |
| 65 | + if (cookies.length == 2) { |
| 66 | + csrftoken = cookies.pop().split(";").shift(); |
| 67 | + } else { |
| 68 | + csrftoken = document.querySelector("[name=csrfmiddlewaretoken]").value; |
| 69 | + } |
| 70 | + if (csrftoken) { |
| 71 | + headers['X-CSRFToken'] = csrftoken |
| 72 | + } |
| 73 | + |
| 74 | + var graphQLFetcher = GraphiQL.createFetcher({ |
64 | 75 | url: fetchURL,
|
65 | 76 | wsClient: graphqlWs.createClient({
|
66 | 77 | url: subscribeURL,
|
67 | 78 | shouldRetry: trueLambda,
|
68 | 79 | lazy: true,
|
69 |
| - }) |
| 80 | + }), |
| 81 | + headers: headers |
70 | 82 | })
|
71 | 83 |
|
72 |
| - function graphQLFetcher(graphQLParams, opts) { |
73 |
| - if (typeof opts === 'undefined') { |
74 |
| - opts = {}; |
75 |
| - } |
76 |
| - var headers = opts.headers || {}; |
77 |
| - headers['Accept'] = headers['Accept'] || 'application/json'; |
78 |
| - headers['Content-Type'] = headers['Content-Type'] || 'application/json'; |
79 |
| - |
80 |
| - // Parse the cookie value for a CSRF token |
81 |
| - var csrftoken; |
82 |
| - var cookies = ("; " + document.cookie).split("; csrftoken="); |
83 |
| - if (cookies.length == 2) { |
84 |
| - csrftoken = cookies.pop().split(";").shift(); |
85 |
| - } else { |
86 |
| - csrftoken = document.querySelector("[name=csrfmiddlewaretoken]").value; |
87 |
| - } |
88 |
| - if (csrftoken) { |
89 |
| - headers['X-CSRFToken'] = csrftoken |
90 |
| - } |
91 |
| - |
92 |
| - opts.headers = headers |
93 |
| - |
94 |
| - return fetcher(graphQLParams, opts) |
95 |
| - } |
96 |
| - |
97 | 84 | // When the query and variables string is edited, update the URL bar so
|
98 | 85 | // that it can be easily shared.
|
99 | 86 | function onEditQuery(newQuery) {
|
|
0 commit comments