Repository URL to install this package:
|
Version:
0.0.6 ▾
|
import { isNonEmptyArray } from 'exotic'
import { GraphQLResponse } from './typings'
/**
* @description we want to validate every graphql request
*/
export const validateGraphQLResponse = <Type extends object = any>(
response: GraphQLResponse<Type>
) => {
if (response.error) {
throw response.error
} else if (isNonEmptyArray(response.errors)) {
throw response.errors[0]
} else if (!response.data) {
console.error('no data')
console.log(response)
// throw new Error(JSON.stringify(response, undefined, 2))
}
}