UNPKG

3.67 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
4
5Object.defineProperty(exports, "__esModule", {
6 value: true
7});
8exports.default = void 0;
9
10var _regenerator = _interopRequireDefault(require("@babel/runtime-corejs2/regenerator"));
11
12var _objectSpread2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/objectSpread"));
13
14var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/asyncToGenerator"));
15
16var _spread = _interopRequireDefault(require("@sharyn/util/spread"));
17
18var _call = _interopRequireDefault(require("./call"));
19
20// flow-disable-next-line
21var graphqlCall =
22/*#__PURE__*/
23function () {
24 var _ref2 = (0, _asyncToGenerator2.default)(
25 /*#__PURE__*/
26 _regenerator.default.mark(function _callee(_ref) {
27 var _callResp, _callResp$data, _callResp2, _callResp2$data, _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;
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 return _context.abrupt("return", (0, _objectSpread2.default)({}, (0, _spread.default)({
62 errors: (_callResp = callResp) === null || _callResp === void 0 ? void 0 : (_callResp$data = _callResp.data) === null || _callResp$data === void 0 ? void 0 : _callResp$data.errors
63 }), mapResp ? mapResp((_callResp2 = callResp) === null || _callResp2 === void 0 ? void 0 : (_callResp2$data = _callResp2.data) === null || _callResp2$data === void 0 ? void 0 : _callResp2$data.data) : (_callResp3 = callResp) === null || _callResp3 === void 0 ? void 0 : (_callResp3$data = _callResp3.data) === null || _callResp3$data === void 0 ? void 0 : _callResp3$data.data));
64
65 case 12:
66 case "end":
67 return _context.stop();
68 }
69 }
70 }, _callee, this, [[2, 8]]);
71 }));
72
73 return function graphqlCall(_x) {
74 return _ref2.apply(this, arguments);
75 };
76}();
77
78var _default = graphqlCall;
79exports.default = _default;
\No newline at end of file