ES5 compatibility

This commit is contained in:
radoslaw.kowalski 2020-08-03 09:16:58 +02:00
parent 49ffbc3716
commit 29f28bc91b

View File

@ -61,29 +61,19 @@
var fetchURL = locationQuery(otherParams); var fetchURL = locationQuery(otherParams);
// Defines a GraphQL fetcher using the fetch API. // Defines a GraphQL fetcher using the fetch API.
function httpClient(graphQLParams, opts = { headers: {} }) { function httpClient(graphQLParams, opts) {
let headers = opts.headers; if (typeof opts === 'undefined') {
// Convert headers to an object. opts = {};
if (typeof headers === 'string') {
headers = JSON.parse(opts.headers);
} }
var headers = opts.headers || {};
headers['Accept'] = headers['Accept'] || 'application/json';
headers['Content-Type'] = headers['Content-Type'] || 'application/json';
if (csrftoken) { if (csrftoken) {
Object.assign( headers['X-CSRFToken'] = csrftoken
{
'X-CSRFToken': csrftoken
},
headers,
)
} }
return fetch(fetchURL, { return fetch(fetchURL, {
method: "post", method: "post",
headers: Object.assign( headers: headers,
{
'Accept': 'application/json',
'Content-Type': 'application/json'
},
headers,
),
body: JSON.stringify(graphQLParams), body: JSON.stringify(graphQLParams),
credentials: "include", credentials: "include",
}) })
@ -120,7 +110,7 @@
var activeSubscription = null; var activeSubscription = null;
// Define a GraphQL fetcher that can intelligently route queries based on the operation type. // Define a GraphQL fetcher that can intelligently route queries based on the operation type.
function graphQLFetcher(graphQLParams, opts = { headers: {} }) { function graphQLFetcher(graphQLParams, opts) {
var operationType = getOperationType(graphQLParams); var operationType = getOperationType(graphQLParams);
// If we're about to execute a new operation, and we have an active subscription, // If we're about to execute a new operation, and we have an active subscription,