UNPKG

@graphql-tools/utils

Version:

Common package containing utils and types for GraphQL tools

27 lines (26 loc) 690 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.mapMaybePromise = mapMaybePromise; const jsutils_js_1 = require("./jsutils.js"); function mapMaybePromise(value, mapper, errorMapper) { if ((0, jsutils_js_1.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); }