Registry / testing / nestjs-graphql-zod

nestjs-graphql-zod

JSON →
library3.4.1jsnpmunverified

A library (v3.4.1) integrating Zod validation objects into NestJS GraphQL resolvers, reducing boilerplate by generating GraphQL types and schemas automatically from Zod schemas. Supports nested objects, enums, custom names, and custom scalar types. Peer dependencies include @nestjs/graphql >=10, @nestjs/core >=8, zod >=3.15, and class-transformer. Key differentiator: eliminates manual DTO/input type classes, with decorators like @QueryWithZod and @ZodArgs that mirror standard NestJS GraphQL decorators but accept Zod objects. Ships TypeScript types.

npm install nestjs-graphql-zod
INSTALL
IMPORT
SIG · NESTJS-GRAPHQL-ZOD
N
nestjs-graphql-zod
testingjavascriptv3.4.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

QueryWithZod
import { QueryWithZod } from 'nestjs-graphql-zod'
const { QueryWithZod } = require('nestjs-graphql-zod')
ESM-only package; no CommonJS support
ZodArgs
import { ZodArgs } from 'nestjs-graphql-zod'
Named export, not default. Also includes type ZodArgsType for parameter types.
modelFromZod
import { modelFromZod } from 'nestjs-graphql-zod'
import { ModelFromZod } from 'nestjs-graphql-zod'
Function name is camelCase, not PascalCase.

Shows how to define a Zod schema, use @QueryWithZod for output validation and @ZodArgs for input validation, and integrate into NestJS GraphQL module.

import { Module } from '@nestjs/common'; import { GraphQLModule } from '@nestjs/graphql'; import { ApolloDriver, ApolloDriverConfig } from '@nestjs/apollo'; import * as zod from 'zod'; import { QueryWithZod, ZodArgs } from 'nestjs-graphql-zod'; const UserZod = zod.object({ id: zod.number().describe('Unique identifier'), name: zod.string().min(1).describe('Full name'), }).describe('User: Represents a user in the system'); @Resolver(of => UserZod) class UserResolver { @QueryWithZod(UserZod, { nullable: true }) async getUser(@Args('id') id: number) { return { id, name: 'John Doe' }; } @MutationWithZod(UserZod) async createUser(@ZodArgs(UserZod) data: zod.infer<typeof UserZod>) { return data; } } @Module({ imports: [ GraphQLModule.forRoot<ApolloDriverConfig>({ driver: ApolloDriver, autoSchemaFile: true, }), ], providers: [UserResolver], }) export class AppModule {}
Debug
Known issues
breakingVersion 3.x requires @nestjs/graphql >=10 (Apollo/GraphQL-Mercurius drivers). Older @nestjs/graphql versions (<10) are incompatible.
fix
Update @nestjs/graphql to >=10.0.0 and use ApolloDriver or MercuriusDriver.
affects: >=3.0.0
deprecatedSome older decorator overloads may be deprecated in favor of the newer decorated input validations. Check migration guides.
fix
Use @ZodArgs and @InputTypeWithZod for input validation instead of manual parsing.
affects: <3.0.0
gotchaZod schemas with `.describe()` are used to generate GraphQL model names. If description is missing or not in `ClassName:Description` format, automatically generated names may conflict or be unclear.
fix
Always provide a description in the format `{ClassName}:{Description}` for nested objects to ensure predictable GraphQL type names.
affects: *
gotchaOutput validation with @QueryWithZod throws if Zod parsing fails. Errors are GraphQL errors but may not include detailed Zod error paths by default.
fix
Implement a custom exception filter or use the `errorFormatter` option provided in some decorators to include Zod error details.
affects: *
Errors
Common errors & fixes
Cannot find module 'nestjs-graphql-zod' or its corresponding type declarations.
Package is ESM-only and requires `"module": "ESNext"` (or similar) in tsconfig.json.
fix
Ensure `"module": "ESNext"` or `"NodeNext"` and `"moduleResolution": "NodeNext"` in your tsconfig.json.
TypeError: Class extends value undefined is not a constructor or null
Missing or incompatible peer dependency (e.g., @nestjs/graphql version mismatch).
fix
Install compatible peer dependencies: `npm install @nestjs/graphql@^10 @nestjs/common@^8 @nestjs/core@^8 zod@^3`.
GraphQLError: Expected value of type "User" but got: [object Object]
Zod schema validation failed for output; returned object does not match schema shape.
fix
Ensure the returned object from resolver matches the exact shape defined in the Zod schema, including required fields and types.
Upgrade
Version history
3.4.1latest on npm
Audit
Dependencies
@nestjs/graphqlrequiredCore NestJS GraphQL module required for decorators and schema generation
@nestjs/corerequiredRequired for NestJS dependency injection and module system
class-transformerrequiredNeeded for transforming plain objects to class instances (used internally)
zodrequiredZod schema validation library; schemas are passed to decorators
Agent activity
4 hits · last 30 days
node
4
Resources
nestjs-graphql-zod — npm install nestjs-graphql-zod · libregistry