UNPKG

11.7 kBSource Map (JSON)View Raw
1{"version":3,"file":"bundle.umd.js","sources":["apollo-fetch.js"],"sourcesContent":["var __assign = (this && this.__assign) || Object.assign || function(t) {\n for (var s, i = 1, n = arguments.length; i < n; i++) {\n s = arguments[i];\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))\n t[p] = s[p];\n }\n return t;\n};\nimport 'cross-fetch/polyfill';\nfunction buildWareStack(funcs, modifiedObject, resolve) {\n var _this = this;\n var next = function () {\n if (funcs.length > 0) {\n var f = funcs.shift();\n if (f) {\n f.apply(_this, [modifiedObject, next]);\n }\n }\n else {\n resolve(modifiedObject);\n }\n };\n next();\n}\nexport function constructDefaultOptions(requestOrRequests, options) {\n var body;\n try {\n body = JSON.stringify(requestOrRequests);\n }\n catch (e) {\n throw new Error(\"Network request failed. Payload is not serializable: \" + e.message);\n }\n return __assign({ body: body, method: 'POST' }, options, { headers: __assign({ Accept: '*/*', 'Content-Type': 'application/json' }, options.headers || []) });\n}\nfunction throwHttpError(response, error) {\n var httpError;\n if (response && response.status >= 300) {\n httpError = new Error(\"Network request failed with status \" + response.status + \" - \\\"\" + response.statusText + \"\\\"\");\n }\n else {\n httpError = new Error(\"Network request failed to return valid JSON\");\n }\n httpError.response = response;\n httpError.parseError = error;\n throw httpError;\n}\nfunction throwBatchError(response) {\n var httpError = new Error(\"A batched Operation of responses for \");\n httpError.response = response;\n throw httpError;\n}\nexport function createApolloFetch(params) {\n if (params === void 0) { params = {}; }\n var constructOptions = params.constructOptions, customFetch = params.customFetch;\n var _uri = params.uri || '/graphql';\n var middlewares = [];\n var batchedMiddlewares = [];\n var afterwares = [];\n var batchedAfterwares = [];\n var applyMiddlewares = function (requestAndOptions, batched) {\n return new Promise(function (resolve, reject) {\n if (batched) {\n buildWareStack(batchedMiddlewares.slice(), requestAndOptions, resolve);\n }\n else {\n buildWareStack(middlewares.slice(), requestAndOptions, resolve);\n }\n });\n };\n var applyAfterwares = function (responseObject, batched) {\n return new Promise(function (resolve, reject) {\n if (batched) {\n buildWareStack(batchedAfterwares.slice(), responseObject, resolve);\n }\n else {\n buildWareStack(afterwares.slice(), responseObject, resolve);\n }\n });\n };\n var apolloFetch = function (request) {\n var options = {};\n var parseError;\n var batched = Array.isArray(request);\n var requestObject = (batched\n ? {\n requests: request,\n options: options,\n }\n : {\n request: request,\n options: options,\n });\n return applyMiddlewares(requestObject, batched)\n .then(function (reqOpts) {\n var construct = constructOptions || constructDefaultOptions;\n var requestOrRequests = reqOpts.request ||\n reqOpts.requests;\n return construct(requestOrRequests, reqOpts.options);\n })\n .then(function (opts) {\n options = __assign({}, opts);\n return (customFetch || fetch)(_uri, options);\n })\n .then(function (response) {\n return response.text().then(function (raw) {\n try {\n var parsed = JSON.parse(raw);\n response.raw = raw;\n response.parsed = parsed;\n return response;\n }\n catch (e) {\n parseError = e;\n response.raw = raw;\n return response;\n }\n });\n })\n .then(function (response) {\n return applyAfterwares({\n response: response,\n options: options,\n }, batched);\n })\n .then(function (_a) {\n var response = _a.response;\n if (response.parsed) {\n if (batched) {\n if (Array.isArray(response.parsed)) {\n return response.parsed;\n }\n else {\n throwBatchError(response);\n }\n }\n else {\n return __assign({}, response.parsed);\n }\n }\n else {\n throwHttpError(response, parseError);\n }\n });\n };\n apolloFetch.use = function (middleware) {\n if (typeof middleware === 'function') {\n middlewares.push(middleware);\n }\n else {\n throw new Error('Middleware must be a function');\n }\n return apolloFetch;\n };\n apolloFetch.useAfter = function (afterware) {\n if (typeof afterware === 'function') {\n afterwares.push(afterware);\n }\n else {\n throw new Error('Afterware must be a function');\n }\n return apolloFetch;\n };\n apolloFetch.batchUse = function (middleware) {\n if (typeof middleware === 'function') {\n batchedMiddlewares.push(middleware);\n }\n else {\n throw new Error('Middleware must be a function');\n }\n return apolloFetch;\n };\n apolloFetch.batchUseAfter = function (afterware) {\n if (typeof afterware === 'function') {\n batchedAfterwares.push(afterware);\n }\n else {\n throw new Error('Afterware must be a function');\n }\n return apolloFetch;\n };\n return apolloFet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