Repository URL to install this package:
|
Version:
1.0.1 ▾
|
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const exotic_1 = require("exotic");
exports.isGraphQueryLanguage = (x) => exotic_1.isObj(x) && exotic_1.isObj(x.data);
exports.EMPTY_ERROR_RESPONSE = Object.freeze({
responseCode: Infinity,
responseMessage: 'failure @@EMPTY',
});
// { response: state: status }
// { data: cart: response: state: status }
// Object.keys(response).length <= 1 => with gql this is always true
// so it needs to handle that
function fromGraphqlOrAnyToResponse(x) {
if (exports.isGraphQueryLanguage(x)) {
if (x.error) {
console.error('[isErrorLikeResponse] response had .error');
return exports.EMPTY_ERROR_RESPONSE;
}
// example:
// { data: { cart: { } } } => cart
const found = Object.keys(x.data).pop();
/**
* means we have a .data that is empty obj
*/
if (found === undefined) {
console.error('[isErrorLikeResponse] obj had .data that was empty');
return exports.EMPTY_ERROR_RESPONSE;
}
else {
const response = x.data[found];
if (response === undefined) {
console.error('[isErrorLikeResponse] obj had .data with the first key that had an invalid value');
return exports.EMPTY_ERROR_RESPONSE;
}
else {
return response;
}
}
}
else {
return x;
}
}
exports.fromGraphqlOrAnyToResponse = fromGraphqlOrAnyToResponse;
//# sourceMappingURL=fromGraphqlOrAnyToResponse.js.map