@grapi/server
Version:
Grapi Schema Generator For GraphQL Server
29 lines (28 loc) • 955 B
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Email = void 0;
const graphql_1 = require("graphql");
const isEmail_1 = __importDefault(require("validator/lib/isEmail"));
const parseAndSerializeValue = (value) => {
if ((0, isEmail_1.default)(value)) {
return value;
}
throw new Error(`Wrong "${value}" email. Does not match the standard`);
};
const parseLiteral = (ast) => {
if ((0, isEmail_1.default)(ast.value)) {
return ast.value;
}
throw new Error(`Wrong "${ast.value}" email. Does not match the standard`);
};
const Email = new graphql_1.GraphQLScalarType({
name: 'Email',
description: 'Email format',
serialize: parseAndSerializeValue,
parseValue: parseAndSerializeValue,
parseLiteral,
});
exports.Email = Email;