import { GraphQLError, GraphQLScalarType, Kind, } from "graphql";
import { z } from "zod";
export const type = "string";
export const typedef = "scalar URL";
export const schema = z.string().url();
export const stringSchema = "z.string().url()";
const urlValidation = (value) => {
    if (typeof value !== "string") {
        throw new GraphQLError(`Value is not iso string: ${JSON.stringify(value)}`);
    }
    const result = schema.safeParse(value);
    if (result.success)
        return result.data;
    throw new GraphQLError(result.error.message);
};
export const config = {
    name: "URL",
    description: "A custom scalar that represents a URL string",
    serialize: urlValidation,
    parseValue: urlValidation,
    parseLiteral: (value) => {
        if (value.kind !== Kind.STRING) {
            throw new GraphQLError("Value is not an string", { nodes: value });
        }
        return urlValidation(value.value);
    },
};
export const scalar = new GraphQLScalarType(config);
//# sourceMappingURL=URL.js.map