Repository URL to install this package:
|
Version:
1.3.2 ▾
|
// import { isErrorLikeResponse as isErrorLikeResponseModules } from '@skava/request/deps/isErrorLikeResponse'
import { isObj, isArray } from 'exotic'
import { isErrorLikeResponse as isErrorLikeResponseModules } from './_isErrorLikeResponse'
import { getOneOf, getOneOfFor } from './_getOneOfFor'
function fromGraphqlOrAnyToResponse(x) {
// Object.isFrozen(x) ||
const isGraphQueryLanguage = (isObj(x) && isObj(x.data))
if (isGraphQueryLanguage) {
if (x.error) {
return true
}
// example:
// { data: { cart: { } } } => cart
const found = Object.keys(x.data).pop()
const response = x.data[found]
return isErrorLikeResponseModules(response)
} else {
return isErrorLikeResponseModules(x)
}
}
// { 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
export function isErrorLikeResponse(x) {
return fromGraphqlOrAnyToResponse(x)
}