mirror of
https://github.com/CamHenlin/MessagesForMacintosh.git
synced 2024-11-29 08:49:40 +00:00
137 lines
5.1 KiB
JavaScript
137 lines
5.1 KiB
JavaScript
'use strict';
|
|
|
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
|
var tslib = require('tslib');
|
|
var printer = require('graphql/language/printer');
|
|
var tsInvariant = require('ts-invariant');
|
|
|
|
var defaultHttpOptions = {
|
|
includeQuery: true,
|
|
includeExtensions: false,
|
|
};
|
|
var defaultHeaders = {
|
|
accept: '*/*',
|
|
'content-type': 'application/json',
|
|
};
|
|
var defaultOptions = {
|
|
method: 'POST',
|
|
};
|
|
var fallbackHttpConfig = {
|
|
http: defaultHttpOptions,
|
|
headers: defaultHeaders,
|
|
options: defaultOptions,
|
|
};
|
|
var throwServerError = function (response, result, message) {
|
|
var error = new Error(message);
|
|
error.name = 'ServerError';
|
|
error.response = response;
|
|
error.statusCode = response.status;
|
|
error.result = result;
|
|
throw error;
|
|
};
|
|
var parseAndCheckHttpResponse = function (operations) { return function (response) {
|
|
return (response
|
|
.text()
|
|
.then(function (bodyText) {
|
|
try {
|
|
return JSON.parse(bodyText);
|
|
}
|
|
catch (err) {
|
|
var parseError = err;
|
|
parseError.name = 'ServerParseError';
|
|
parseError.response = response;
|
|
parseError.statusCode = response.status;
|
|
parseError.bodyText = bodyText;
|
|
return Promise.reject(parseError);
|
|
}
|
|
})
|
|
.then(function (result) {
|
|
if (response.status >= 300) {
|
|
throwServerError(response, result, "Response not successful: Received status code " + response.status);
|
|
}
|
|
if (!Array.isArray(result) &&
|
|
!result.hasOwnProperty('data') &&
|
|
!result.hasOwnProperty('errors')) {
|
|
throwServerError(response, result, "Server response was missing for query '" + (Array.isArray(operations)
|
|
? operations.map(function (op) { return op.operationName; })
|
|
: operations.operationName) + "'.");
|
|
}
|
|
return result;
|
|
}));
|
|
}; };
|
|
var checkFetcher = function (fetcher) {
|
|
if (!fetcher && typeof fetch === 'undefined') {
|
|
var library = 'unfetch';
|
|
if (typeof window === 'undefined')
|
|
library = 'node-fetch';
|
|
throw process.env.NODE_ENV === "production" ? new tsInvariant.InvariantError(1) : new tsInvariant.InvariantError("\nfetch is not found globally and no fetcher passed, to fix pass a fetch for\nyour environment like https://www.npmjs.com/package/" + library + ".\n\nFor example:\nimport fetch from '" + library + "';\nimport { createHttpLink } from 'apollo-link-http';\n\nconst link = createHttpLink({ uri: '/graphql', fetch: fetch });");
|
|
}
|
|
};
|
|
var createSignalIfSupported = function () {
|
|
if (typeof AbortController === 'undefined')
|
|
return { controller: false, signal: false };
|
|
var controller = new AbortController();
|
|
var signal = controller.signal;
|
|
return { controller: controller, signal: signal };
|
|
};
|
|
var selectHttpOptionsAndBody = function (operation, fallbackConfig) {
|
|
var configs = [];
|
|
for (var _i = 2; _i < arguments.length; _i++) {
|
|
configs[_i - 2] = arguments[_i];
|
|
}
|
|
var options = tslib.__assign({}, fallbackConfig.options, { headers: fallbackConfig.headers, credentials: fallbackConfig.credentials });
|
|
var http = fallbackConfig.http;
|
|
configs.forEach(function (config) {
|
|
options = tslib.__assign({}, options, config.options, { headers: tslib.__assign({}, options.headers, config.headers) });
|
|
if (config.credentials)
|
|
options.credentials = config.credentials;
|
|
http = tslib.__assign({}, http, config.http);
|
|
});
|
|
var operationName = operation.operationName, extensions = operation.extensions, variables = operation.variables, query = operation.query;
|
|
var body = { operationName: operationName, variables: variables };
|
|
if (http.includeExtensions)
|
|
body.extensions = extensions;
|
|
if (http.includeQuery)
|
|
body.query = printer.print(query);
|
|
return {
|
|
options: options,
|
|
body: body,
|
|
};
|
|
};
|
|
var serializeFetchParameter = function (p, label) {
|
|
var serialized;
|
|
try {
|
|
serialized = JSON.stringify(p);
|
|
}
|
|
catch (e) {
|
|
var parseError = process.env.NODE_ENV === "production" ? new tsInvariant.InvariantError(2) : new tsInvariant.InvariantError("Network request failed. " + label + " is not serializable: " + e.message);
|
|
parseError.parseError = e;
|
|
throw parseError;
|
|
}
|
|
return serialized;
|
|
};
|
|
var selectURI = function (operation, fallbackURI) {
|
|
var context = operation.getContext();
|
|
var contextURI = context.uri;
|
|
if (contextURI) {
|
|
return contextURI;
|
|
}
|
|
else if (typeof fallbackURI === 'function') {
|
|
return fallbackURI(operation);
|
|
}
|
|
else {
|
|
return fallbackURI || '/graphql';
|
|
}
|
|
};
|
|
|
|
exports.checkFetcher = checkFetcher;
|
|
exports.createSignalIfSupported = createSignalIfSupported;
|
|
exports.fallbackHttpConfig = fallbackHttpConfig;
|
|
exports.parseAndCheckHttpResponse = parseAndCheckHttpResponse;
|
|
exports.selectHttpOptionsAndBody = selectHttpOptionsAndBody;
|
|
exports.selectURI = selectURI;
|
|
exports.serializeFetchParameter = serializeFetchParameter;
|
|
exports.throwServerError = throwServerError;
|
|
//# sourceMappingURL=bundle.cjs.js.map
|