@terabits/grapi
Version:
Grapi Schema Generator For GraphQL Server
33 lines (32 loc) • 958 B
JavaScript
;
exports.__esModule = true;
exports.Url = void 0;
var graphql_1 = require("graphql");
var validator_1 = require("validator");
var options = {
protocols: ['http', 'https'],
require_protocol: true,
require_valid_protocol: true,
require_host: true,
allow_underscores: true
};
var serializeAndSerialize = function (value) {
if ((0, validator_1.isURL)(value, options)) {
return value;
}
throw new Error("Malformed \"".concat(value, "\" Url, not match with standard"));
};
var parseLiteral = function (ast) {
if ((0, validator_1.isURL)(ast.value, options)) {
return ast.value;
}
throw new Error("Malformed \"".concat(ast.value, "\" Url, not match with standard"));
};
var Url = new graphql_1.GraphQLScalarType({
name: 'Url',
description: 'Url format',
serialize: serializeAndSerialize,
parseValue: serializeAndSerialize,
parseLiteral: parseLiteral
});
exports.Url = Url;