1 | "use strict";
|
2 |
|
3 | var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
|
4 |
|
5 | Object.defineProperty(exports, "__esModule", {
|
6 | value: true
|
7 | });
|
8 | exports.default = void 0;
|
9 |
|
10 | var _regenerator = _interopRequireDefault(require("@babel/runtime-corejs2/regenerator"));
|
11 |
|
12 | var _objectSpread2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/objectSpread"));
|
13 |
|
14 | var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/asyncToGenerator"));
|
15 |
|
16 | var _spread = _interopRequireDefault(require("@sharyn/util/spread"));
|
17 |
|
18 | var _call = _interopRequireDefault(require("./call"));
|
19 |
|
20 |
|
21 | var graphqlCall =
|
22 |
|
23 | function () {
|
24 | var _ref2 = (0, _asyncToGenerator2.default)(
|
25 |
|
26 | _regenerator.default.mark(function _callee(_ref) {
|
27 | var _callResp3, _callResp3$data;
|
28 |
|
29 | var urlBase, urlPath, authorizationBearer, cookie, _ref$urlParams, urlParams, mapUrlParams, _ref$fields, fields, mapFields, query, mapResp, callResp, variables, _err$response, _err$response$data, dataResp, _callResp, _callResp$data, _callResp2, _callResp2$data;
|
30 |
|
31 | return _regenerator.default.wrap(function _callee$(_context) {
|
32 | while (1) {
|
33 | switch (_context.prev = _context.next) {
|
34 | case 0:
|
35 | urlBase = _ref.urlBase, urlPath = _ref.urlPath, authorizationBearer = _ref.authorizationBearer, cookie = _ref.cookie, _ref$urlParams = _ref.urlParams, urlParams = _ref$urlParams === void 0 ? {} : _ref$urlParams, mapUrlParams = _ref.mapUrlParams, _ref$fields = _ref.fields, fields = _ref$fields === void 0 ? {} : _ref$fields, mapFields = _ref.mapFields, query = _ref.query, mapResp = _ref.mapResp;
|
36 | variables = (0, _objectSpread2.default)({}, mapUrlParams ? mapUrlParams(urlParams) : urlParams, mapFields ? mapFields(fields) : fields);
|
37 | _context.prev = 2;
|
38 | _context.next = 5;
|
39 | return (0, _call.default)({
|
40 | urlBase: urlBase,
|
41 | urlPath: urlPath,
|
42 | authorizationBearer: authorizationBearer,
|
43 | cookie: cookie,
|
44 | body: {
|
45 | query: query,
|
46 | variables: variables
|
47 | }
|
48 | });
|
49 |
|
50 | case 5:
|
51 | callResp = _context.sent;
|
52 | _context.next = 11;
|
53 | break;
|
54 |
|
55 | case 8:
|
56 | _context.prev = 8;
|
57 | _context.t0 = _context["catch"](2);
|
58 | 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;
|
59 |
|
60 | case 11:
|
61 | dataResp = {};
|
62 |
|
63 | try {
|
64 | dataResp = mapResp ? mapResp((_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;
|
65 | } catch (err) {
|
66 |
|
67 | console.error(err);
|
68 | }
|
69 |
|
70 | return _context.abrupt("return", (0, _objectSpread2.default)({}, (0, _spread.default)({
|
71 | errors: (_callResp3 = callResp) === null || _callResp3 === void 0 ? void 0 : (_callResp3$data = _callResp3.data) === null || _callResp3$data === void 0 ? void 0 : _callResp3$data.errors
|
72 | }), dataResp));
|
73 |
|
74 | case 14:
|
75 | case "end":
|
76 | return _context.stop();
|
77 | }
|
78 | }
|
79 | }, _callee, this, [[2, 8]]);
|
80 | }));
|
81 |
|
82 | return function graphqlCall(_x) {
|
83 | return _ref2.apply(this, arguments);
|
84 | };
|
85 | }();
|
86 |
|
87 | var _default = graphqlCall;
|
88 | exports.default = _default; |
\ | No newline at end of file |