UNPKG

@grapi/server

Version:

Grapi Schema Generator For GraphQL Server

36 lines (35 loc) 1.12 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Url = void 0; const graphql_1 = require("graphql"); const isURL_1 = __importDefault(require("validator/lib/isURL")); const options = { protocols: ['http', 'https'], require_protocol: true, require_valid_protocol: true, require_host: true, allow_underscores: true, }; const serializeAndSerialize = (value) => { if ((0, isURL_1.default)(value, options)) { return value; } throw new Error(`Malformed "${value}" Url, not match with standard`); }; const parseLiteral = (ast) => { if ((0, isURL_1.default)(ast.value, options)) { return ast.value; } throw new Error(`Malformed "${ast.value}" Url, not match with standard`); }; const Url = new graphql_1.GraphQLScalarType({ name: 'Url', description: 'Url format', serialize: serializeAndSerialize, parseValue: serializeAndSerialize, parseLiteral, }); exports.Url = Url;