UNPKG

@atlaskit/profilecard

Version:

A React component to display a card with user information.

118 lines (116 loc) 4.67 kB
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator"; import _regeneratorRuntime from "@babel/runtime/regenerator"; import { HttpError } from '../util/errors'; import { handleAGGErrors, handleDirectoryGraphQLErrors } from './errorUtils'; var buildHeaders = function buildHeaders() { var headers = new Headers(); headers.append('Content-Type', 'application/json'); return headers; }; var id = function id(headers) { return headers; }; /** * @param {string} serviceUrl - GraphQL service endpoint * @param {Query} query - GraphQL query * @param {HeaderProcessor} processHeaders - a function to add extra headers to the request */ export function directoryGraphqlQuery(_x, _x2) { return _directoryGraphqlQuery.apply(this, arguments); } /** * @param {string} serviceUrl - GraphQL service endpoint * @param {Query} query - GraphQL query * @param {HeaderProcessor} processHeaders - a function to add extra headers to the request */ function _directoryGraphqlQuery() { _directoryGraphqlQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(serviceUrl, query) { var processHeaders, _args = arguments; return _regeneratorRuntime.wrap(function _callee$(_context) { while (1) switch (_context.prev = _context.next) { case 0: processHeaders = _args.length > 2 && _args[2] !== undefined ? _args[2] : id; return _context.abrupt("return", graphQLQuery(serviceUrl, query, processHeaders, handleDirectoryGraphQLErrors)); case 2: case "end": return _context.stop(); } }, _callee); })); return _directoryGraphqlQuery.apply(this, arguments); } export function AGGQuery(_x3, _x4) { return _AGGQuery.apply(this, arguments); } function _AGGQuery() { _AGGQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(serviceUrl, query) { var processHeaders, _args2 = arguments; return _regeneratorRuntime.wrap(function _callee2$(_context2) { while (1) switch (_context2.prev = _context2.next) { case 0: processHeaders = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : id; return _context2.abrupt("return", graphQLQuery(serviceUrl, query, processHeaders, handleAGGErrors)); case 2: case "end": return _context2.stop(); } }, _callee2); })); return _AGGQuery.apply(this, arguments); } function graphQLQuery(_x5, _x6) { return _graphQLQuery.apply(this, arguments); } function _graphQLQuery() { _graphQLQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(serviceUrl, query) { var _response$headers; var processHeaders, handleErrors, headers, response, traceIdFromHeaders, json, _json$extensions$gate, _json$extensions, _args3 = arguments; return _regeneratorRuntime.wrap(function _callee3$(_context3) { while (1) switch (_context3.prev = _context3.next) { case 0: processHeaders = _args3.length > 2 && _args3[2] !== undefined ? _args3[2] : id; handleErrors = _args3.length > 3 ? _args3[3] : undefined; headers = processHeaders(buildHeaders()); _context3.next = 5; return fetch(new Request(serviceUrl, { method: 'POST', credentials: 'include', mode: 'cors', headers: headers, body: JSON.stringify(query) })); case 5: response = _context3.sent; traceIdFromHeaders = response === null || response === void 0 || (_response$headers = response.headers) === null || _response$headers === void 0 ? void 0 : _response$headers.get('atl-traceid'); if (response.ok) { _context3.next = 9; break; } throw new HttpError(response.status, response.statusText, traceIdFromHeaders); case 9: _context3.next = 11; return response.json(); case 11: json = _context3.sent; if (json.errors) { handleErrors(json.errors, (_json$extensions$gate = (_json$extensions = json.extensions) === null || _json$extensions === void 0 || (_json$extensions = _json$extensions.gateway) === null || _json$extensions === void 0 ? void 0 : _json$extensions.request_id) !== null && _json$extensions$gate !== void 0 ? _json$extensions$gate : traceIdFromHeaders); } return _context3.abrupt("return", json.data); case 14: case "end": return _context3.stop(); } }, _callee3); })); return _graphQLQuery.apply(this, arguments); }