apollo-server-throw-if
A library that throws Apollo Server exceptions when validations fail.
Usage
Install module
npm install --save apollo-server-throw-if
Sample
const throwIf = require('apollo-server-throw-if')
throwIf.invalidDateInMs('2043-01-01', 'lastUpdate')
Functions
Functions | Description |
---|
invalidDateInMs(value, argumentName) | Throws if: - value is not a number - value can not be parsed by new Date(value) |
invalidFirestoreId(id, objectName) | Throws if: - not a valid Firestore id (20 characters a-z, A-Z, and 0-9) |
invalidShortDate(value, argumentName) | Expects a date with the format (YYYY-MM-DD). Throws if: - value is not a string with exactly 10 characters - value can not be parsed by new Date(value) |
invalidTrimmedNonEmptyString(value, argumentName) | Throws if: - value is not a string - value is not trimmed - string is empty |
| objectDoesNotContain(object, objectName, properties)
| Throws if any of the property names listed in properties
are not in object
|
| objectUpdatesHaveUnchangedProperties(objectUpdates, objectUpdatesName, originalObject)
| Throws if any of the propertes in the objectUpdates has the same value as in originalObject
. Change validation uses ==
as opposed to ===
and only works for objects that does not contain nested objects. |
| outOfSync(localLastUpdated, serverLastUpdated)
| Throws if:
- any of the provided dates is not a valid date
- dates are not the same|