npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@vyrel/morph

v0.1.1

Published

Type-safe bridge from Zod schemas to Pothos GraphQL object fields, args, and inputs

Readme

@vyrel/morph

Type-safe bridge from Zod schemas to Pothos GraphQL object fields, args, and inputs.

Use one Zod row/model schema as the source of truth, then expose GraphQL fields, list filters, and mutation inputs without hand-mapping every column.

bun add @vyrel/morph
bun add @pothos/core @pothos/plugin-validation @pothos/plugin-with-input zod

@vyrel/logging is an optional peer. When present, unmapped-field warnings use structured logs; otherwise the package falls back to console.warn.

Why

In a Drizzle + Zod + Pothos stack you often redefine the same shape three times:

  1. database / Zod row schema
  2. GraphQL object fields
  3. mutation inputs and query args

@vyrel/morph derives the GraphQL surface from Zod:

  • object field exposure (exposeFields)
  • withInput mutation fields (inputsFrom)
  • query/list args (argsFrom / listArgsSchema)
  • enum registration from z.enum / z.literal

You keep control of resolvers, relations, and custom scalars.

Quick start

import SchemaBuilder from "@pothos/core";
import ValidationPlugin from "@pothos/plugin-validation";
import WithInputPlugin from "@pothos/plugin-with-input";
import { initializeDrizzleGraphqlBridge } from "@vyrel/morph";
import { z } from "zod/v4";

const builder = new SchemaBuilder({
  plugins: [ValidationPlugin, WithInputPlugin],
});

const bridge = initializeDrizzleGraphqlBridge(builder, {
  defaultIdFields: ["id", "orgId"],
});

const taskRowSchema = z.object({
  id: z.string(),
  title: z.string(),
  completed: z.boolean(),
  status: z.enum(["todo", "done"]),
});

const taskGraphql = bridge.model({
  objectName: "Task",
  rowSchema: taskRowSchema,
  listArgsSchema: {
    filters: z.object({
      status: z.enum(["todo", "done"]).optional(),
    }),
  },
});

const Task = builder.objectRef<z.infer<typeof taskRowSchema>>("Task");

builder.objectType(Task, {
  fields: (t) => ({
    ...taskGraphql.exposeFields(t),
  }),
});

builder.mutationFields((t) => ({
  createTask: t.fieldWithInput({
    input: {
      ...taskGraphql.inputsFrom(
        taskRowSchema.omit({ id: true })
      ),
    },
    resolve: () => {
      throw new Error("Implement me");
    },
    type: Task,
  }),
}));

API

initializeDrizzleGraphqlBridge(builder, options?)

Creates a bridge bound to your Pothos builder.

| Option | Description | | --- | --- | | defaultIdFields | Column names exposed as GraphQL ID. When omitted on both bridge and model, defaults to ["id", "orgId"]. | | unmappedFields | Optional. "throw" (default), "warn", or "omit" when a Zod field cannot map to GraphQL. |

Scalars already registered on the Pothos builder are discovered automatically. Enum GraphQL names default to `${objectName}${PascalCase(field)}`; override per model with enumName.

Returns:

| Method | Description | | --- | --- | | bridge.model(config) | Model helpers for a Zod row schema | | bridge.fields(config) | Alias of model | | bridge.inputsFrom(schema, options?) | Shared input mapper (no model binding) |

bridge.model(config)

| Option | Description | | --- | --- | | rowSchema | Zod object schema for the row | | objectName | GraphQL type name used for enum registration | | exclude | Row keys omitted from GraphQL exposure | | idFields | Override ID columns for this model | | listArgsSchema | Named Zod schemas converted to query/list args | | extraEnums / extraEnumsFrom | Register additional enum sources | | computedEnumFields | Resolver-backed enum fields | | unmappedFields | Per-model override of the bridge policy |

Model helpers:

| Helper | Description | | --- | --- | | exposeFields(t, options?) | Map row columns to Pothos object fields | | inputsFrom(schema, options?) | Map a Zod schema to withInput fields | | argsFrom(schema, options?) | Map a Zod schema to field args | | args | Pre-built args when listArgsSchema is configured | | connection({ type, name?, pageInfoName?, fields? }) | Forward-cursor Connection + PageInfo objects |

model.connection(options)

Creates GraphQL types for forward-cursor pagination (not full Relay):

const TaskConnection = taskGraphql.connection({ type: TaskObject });
// TaskConnection { nodes, pageInfo }
// TaskPageInfo { endCursor, hasNextPage }

| Option | Description | | --- | --- | | type | Pothos node object type for nodes | | name | Connection type name (default `${objectName}Connection`) | | pageInfoName | PageInfo type name (default `${objectName}PageInfo`) | | fields | Optional extra fields on the Connection object |

Also exported: ConnectionPayload<TNode> and ConnectionPageInfo for typing service return values.

z.array(z.string()) maps to [String]; z.array(z.enum(...)) reuses a matching builder enum as a list.

Common inputsFrom / argsFrom options:

  • exclude — omit keys
  • fieldTypes — per-field GraphQL type overrides (scalars, ambiguous enums, lists)
  • required — force required/optional GraphQL input fields
  • unmappedFields — local policy override

Mapping behavior

| Zod | GraphQL | | --- | --- | | z.string() | String, or ID when the key is in idFields | | z.boolean() | Boolean | | z.number() | Float / Int (inferred) | | z.date() | DateTime when registered | | z.enum() / z.literal() | Generated GraphQL enums | | z.array(z.string()) | [String] | | z.array(z.enum(...)) | [ExistingEnum] when values match a builder enum | | nullable / optional Zod | Nullable GraphQL fields | | .describe() | GraphQL field description |

Unmapped Zod types follow unmappedFields (throw by default).

What this package does not do

  • It does not replace Pothos, Zod, or Drizzle.
  • It does not generate resolvers or authorization.
  • It does not invent relation fields — add those manually next to exposeFields.
  • It does not run GraphQL Codegen (that belongs on the client with @vyrel/graphql-client).

License

MIT