@graphql-tools/utils
Version:
Common package containing utils and types for GraphQL tools
24 lines (23 loc) • 555 B
JavaScript
import { isPromise } from './jsutils.js';
export function mapMaybePromise(value, mapper, errorMapper) {
if (isPromise(value)) {
if (errorMapper) {
try {
return value.then(mapper, errorMapper);
}
catch (e) {
return errorMapper(e);
}
}
return value.then(mapper);
}
if (errorMapper) {
try {
return mapper(value);
}
catch (e) {
return errorMapper(e);
}
}
return mapper(value);
}