1 | "use strict";
|
2 |
|
3 | var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
|
4 |
|
5 | var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
|
6 |
|
7 | _Object$defineProperty(exports, "__esModule", {
|
8 | value: true
|
9 | });
|
10 |
|
11 | exports["default"] = void 0;
|
12 |
|
13 | var _regenerator = _interopRequireDefault(require("@babel/runtime-corejs2/regenerator"));
|
14 |
|
15 | var _objectSpread2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/objectSpread"));
|
16 |
|
17 | var _keys = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/keys"));
|
18 |
|
19 | var _stringify = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/json/stringify"));
|
20 |
|
21 | var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/asyncToGenerator"));
|
22 |
|
23 | var _spread = _interopRequireDefault(require("@sharyn/util/spread"));
|
24 |
|
25 | var _call = _interopRequireDefault(require("./call"));
|
26 |
|
27 |
|
28 | var graphqlCall =
|
29 |
|
30 | function () {
|
31 | var _ref2 = (0, _asyncToGenerator2["default"])(
|
32 |
|
33 | _regenerator["default"].mark(function _callee(_ref) {
|
34 | var _callResp3, _callResp3$data;
|
35 |
|
36 | var urlBase, urlPath, authorizationBearer, cookie, _ref$variables, variables, query, mapRespData, _ref$extraBody, extraBody, withCredentials, cancelToken, _ref$axiosOptions, axiosOptions, callResp, formData, _err$response, _err$response$data, dataResp, _callResp, _callResp$data, _callResp2, _callResp2$data;
|
37 |
|
38 | return _regenerator["default"].wrap(function _callee$(_context) {
|
39 | while (1) {
|
40 | switch (_context.prev = _context.next) {
|
41 | case 0:
|
42 | urlBase = _ref.urlBase, urlPath = _ref.urlPath, authorizationBearer = _ref.authorizationBearer, cookie = _ref.cookie, _ref$variables = _ref.variables, variables = _ref$variables === void 0 ? {} : _ref$variables, query = _ref.query, mapRespData = _ref.mapRespData, _ref$extraBody = _ref.extraBody, extraBody = _ref$extraBody === void 0 ? {} : _ref$extraBody, withCredentials = _ref.withCredentials, cancelToken = _ref.cancelToken, _ref$axiosOptions = _ref.axiosOptions, axiosOptions = _ref$axiosOptions === void 0 ? {} : _ref$axiosOptions;
|
43 | formData = new FormData();
|
44 | formData.append('query', query);
|
45 | formData.append('variables', (0, _stringify["default"])(variables));
|
46 | (0, _keys["default"])(extraBody).forEach(function (key) {
|
47 | return formData.append(key, extraBody[key]);
|
48 | });
|
49 | _context.prev = 5;
|
50 | _context.next = 8;
|
51 | return (0, _call["default"])({
|
52 | urlBase: urlBase,
|
53 | urlPath: urlPath,
|
54 | authorizationBearer: authorizationBearer,
|
55 | cookie: cookie,
|
56 | body: formData,
|
57 | axiosOptions: axiosOptions,
|
58 | withCredentials: withCredentials,
|
59 | cancelToken: cancelToken
|
60 | });
|
61 |
|
62 | case 8:
|
63 | callResp = _context.sent;
|
64 | _context.next = 14;
|
65 | break;
|
66 |
|
67 | case 11:
|
68 | _context.prev = 11;
|
69 | _context.t0 = _context["catch"](5);
|
70 | throw ((_err$response = _context.t0.response) === null || _err$response === void 0 ? void 0 : (_err$response$data = _err$response.data) === null || _err$response$data === void 0 ? void 0 : _err$response$data.errors) ? _context.t0.response.data.errors[0] : _context.t0;
|
71 |
|
72 | case 14:
|
73 | dataResp = {};
|
74 |
|
75 | try {
|
76 | dataResp = mapRespData ? mapRespData((_callResp = callResp) === null || _callResp === void 0 ? void 0 : (_callResp$data = _callResp.data) === null || _callResp$data === void 0 ? void 0 : _callResp$data.data) : (_callResp2 = callResp) === null || _callResp2 === void 0 ? void 0 : (_callResp2$data = _callResp2.data) === null || _callResp2$data === void 0 ? void 0 : _callResp2$data.data;
|
77 | } catch (err) {
|
78 |
|
79 | console.error(err);
|
80 | }
|
81 |
|
82 | return _context.abrupt("return", (0, _objectSpread2["default"])({}, (0, _spread["default"])({
|
83 | errors: (_callResp3 = callResp) === null || _callResp3 === void 0 ? void 0 : (_callResp3$data = _callResp3.data) === null || _callResp3$data === void 0 ? void 0 : _callResp3$data.errors
|
84 | }), dataResp));
|
85 |
|
86 | case 17:
|
87 | case "end":
|
88 | return _context.stop();
|
89 | }
|
90 | }
|
91 | }, _callee, null, [[5, 11]]);
|
92 | }));
|
93 |
|
94 | return function graphqlCall(_x) {
|
95 | return _ref2.apply(this, arguments);
|
96 | };
|
97 | }();
|
98 |
|
99 | var _default = graphqlCall;
|
100 | exports["default"] = _default; |
\ | No newline at end of file |