@rachelallyson/prisma-pothos-inputs
v1.2.0
Published
Generate Pothos schema types from your Prisma schema — scalars, enums, WhereInput, OrderBy, FindManyArgs; Prisma-typed refs so you can pass args straight to the client.
Maintainers
Readme
@rachelallyson/prisma-pothos-inputs
Generate Pothos schema types from your Prisma schema.
Scalars, enums, filters, OrderBy, FindManyArgs, Create/Update inputs — with optional Prisma-typed refs so you can pass args straight to the client. Built for Prisma v7 (works with v5/v6).
What it does
@rachelallyson/prisma-pothos-inputs reads your Prisma schema and emits TypeScript that registers types with your Pothos SchemaBuilder. You get:
- Scalars — e.g.
DateTime(extensible forJSON, etc.) - Enums — every Prisma
enumplus a sharedSortOrder(asc/desc) - Per-model input types —
WhereInput,WhereUniqueInput(including compound uniques and compound primary keys@@id([a, b])),OrderByInput(object shape matching Prisma),FindManyArgs(where, orderBy, skip, take),CreateInput,UpdateInput - Relation-style create inputs (optional) — With
useRelationInputs: true, create inputs use Prisma-style nested relations:author: { connect: { id } },create: { ... },connectOrCreate: { where, create }instead of raw FK fields likeauthorId. Ref types becomePrisma.PostCreateInputwhenprismaClientPathis set. - Filter inputs —
StringFilter,IntFilter,DateTimeFilter, enum filters, list/relation filters soWhereInputmatches Prisma’s shape
When you pass --prisma-client-path (or prismaClientPath in the API), the generated refs are typed as Prisma.UserCreateInput, Prisma.PostFindManyArgs, etc., so resolvers get correct types and you can spread args directly into the Prisma client.
Table of contents
Installation
npm install @rachelallyson/prisma-pothos-inputsRequirements: Node.js 18+, a Prisma schema, and Pothos. The package uses @mrleebo/prisma-ast to parse your schema; no Prisma CLI is required at runtime.
Quick start
- Generate Pothos types (writes a single file that registers scalars, enums, and input types):
npx @rachelallyson/prisma-pothos-inputs --schema prisma/schema.prisma --output-pothos src/__generated__/pothos-inputs.ts- Optional: type refs as Prisma so resolvers receive
args.data/args.inputas the correct Prisma types:
npx @rachelallyson/prisma-pothos-inputs --schema prisma/schema.prisma --output-pothos src/__generated__/pothos-inputs.ts --prisma-client-path ../../generated/prisma/client.jsUse a path relative to the generated file so the import resolves.
- In your Pothos schema: call
registerPothosTypes(builder)and use the returned refs for args (e.g.refs.UserCreateInputType,refs.PostFindManyArgs). WithprismaClientPathset, you can pass args straight to Prisma (e.g.prisma.post.findMany({ ...query, ...(args.input ?? {}) })).
Usage
CLI
| Option | Description |
|--------|-------------|
| --schema <path> | Path to Prisma schema file. Default: prisma/schema.prisma. |
| --output-pothos <path> | Write Pothos types (scalars, enums, input types) to this file. |
| --prisma-client-path <path> | Path to Prisma client for typed input refs. Use with --output-pothos. |
| --use-relation-inputs | Use connect/create/connectOrCreate nested inputs instead of FK scalars. Use with --output-pothos. |
| --output-pothos-enums <path> | Write Pothos enum registration only to this file. |
| --help, -h | Print usage and exit. |
You must specify at least one of --output-pothos or --output-pothos-enums.
Examples:
# Full Pothos types
npx @rachelallyson/prisma-pothos-inputs --output-pothos src/__generated__/pothos-inputs.ts
# With Prisma-typed refs
npx @rachelallyson/prisma-pothos-inputs --output-pothos src/__generated__/pothos-inputs.ts --prisma-client-path ../../generated/prisma/client.js
# Enums only
npx @rachelallyson/prisma-pothos-inputs --output-pothos-enums src/__generated__/pothos-enums.tsProgrammatic API
One-shot: schema string → Pothos TypeScript
import { generatePothosFromSchema } from '@rachelallyson/prisma-pothos-inputs';
import { readFileSync } from 'fs';
const schemaSource = readFileSync('prisma/schema.prisma', 'utf-8');
const ts = generatePothosFromSchema(schemaSource, {
prismaClientPath: '../../generated/prisma/client.js', // optional
useRelationInputs: true, // optional: connect/create/connectOrCreate instead of FK scalars
});Two-step: parse then generate
import { parsePrismaSchema, generatePothosSchema } from '@rachelallyson/prisma-pothos-inputs';
const normalized = parsePrismaSchema(schemaSource);
const ts = generatePothosSchema(normalized, { prismaClientPath: '...' });Exports:
generatePothosFromSchema(schemaSource, options?)— Parse + generate in one call.- Options (
GeneratePothosSchemaOptions):prismaClientPath?— path to Prisma client for typed refs;useRelationInputs?(defaultfalse) — whentrue, CreateInput uses nested relation inputs (connect,create,connectOrCreate) and omits FK scalars, and refs are typed asPrisma.PostCreateInputetc. writePothosInputs(options)— Async. Read schema from disk, generate, and write the file. Use at server startup so you don’t need a separate generate script (see below).parsePrismaSchema(schemaSource)— Parse only; returnsNormalizedSchema(models + enums).generatePothosSchema(normalized, options?)— Generate from aNormalizedSchema.generatePothosEnums(normalized)— Enum registration only.- Types:
NormalizedSchema,NormalizedModel,NormalizedEnum,GeneratePothosSchemaOptions,WritePothosInputsOptions,PothosEnumBuilder. PRISMA_SCALAR_TO_GRAPHQL,CUSTOM_SCALARS— Mapping and scalar names.
Generate at server startup
Generate the Pothos inputs file when the server starts so you don’t need a separate script. Call writePothosInputs before importing your schema:
// server.ts or index.ts — entry point
import { writePothosInputs } from '@rachelallyson/prisma-pothos-inputs';
import { fileURLToPath } from 'node:url';
import { dirname, join } from 'node:path';
const __dirname = dirname(fileURLToPath(import.meta.url));
await writePothosInputs({
schemaPath: join(__dirname, 'prisma/schema.prisma'),
outputPath: join(__dirname, 'src/__generated__/pothos-inputs.ts'),
prismaClientPath: '../../generated/prisma/client.js',
cwd: join(__dirname, '..'), // optional; defaults to process.cwd()
});
const { schema } = await import('./src/schema.js');
// Start your GraphQL server with schema...Run the entry point with tsx (or similar) so the newly written file is loaded when the schema module is imported.
Build integration
Run after Prisma generate:
{
"scripts": {
"generate": "prisma generate && npx @rachelallyson/prisma-pothos-inputs --schema prisma/schema.prisma --output-pothos src/__generated__/pothos-inputs.ts --prisma-client-path ../../generated/prisma/client.js"
}
}See docs/EXAMPLES.md for the full Pothos example.
What gets generated
With --output-pothos you get a single file that exports registerPothosTypes(builder). It:
- Registers scalars (e.g.
DateTime). - Registers enums: each Prisma enum (e.g.
Role) and a shared SortOrder (asc,desc). - Registers per-model input types:
- OrderByInput — one optional
SortOrderfield per sortable column (same shape as Prisma; passorderBy: args.orderBy). - FindManyArgs — optional
where,orderBy,skip,take(single input so you can...(args.input ?? {})). - WhereInput / WhereUniqueInput — AND/OR/NOT plus scalar and relation filters; compound uniques for
@@unique([a, b])and compound primary keys@@id([a, b]). - CreateInput / UpdateInput — scalar and enum fields (relations via foreign keys where applicable).
- OrderByInput — one optional
When --prisma-client-path is set, the return type of registerPothosTypes declares refs as InputTypeRef<..., Prisma.UserCreateInput>, etc., so Pothos infers correct types in resolvers.
Documentation
Full docs: rachelallyson.github.io/prisma-pothos-inputs
- Getting started — Install, first run, wiring into your Pothos schema.
- API reference — Programmatic API and options.
- Examples — Scripts, direct args, generate at startup.
- Type mapping — Prisma → GraphQL mapping.
Testing
npm testRuns the test suite (Node’s built-in test runner) after building. Tests cover parsing, Pothos schema generation (with and without prismaClientPath), and enums.
License
MIT
