UNPKG

@graphql-mesh/transport-rest

Version:
26 lines (25 loc) 981 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.processLengthAnnotations = processLengthAnnotations; function processLengthAnnotations(scalar, { min: minLength, max: maxLength, }) { function coerceString(value) { if (value != null) { const vStr = value.toString(); if (typeof minLength !== 'undefined' && vStr.length < minLength) { throw new Error(`${scalar.name} cannot be less than ${minLength} but given ${vStr}`); } if (typeof maxLength !== 'undefined' && vStr.length > maxLength) { throw new Error(`${scalar.name} cannot be more than ${maxLength} but given ${vStr}`); } return vStr; } } scalar.serialize = coerceString; scalar.parseValue = coerceString; scalar.parseLiteral = ast => { if ('value' in ast) { return coerceString(ast.value); } return null; }; }