Nestjs Graphql Zod

screenshot of Nestjs Graphql Zod
nestjs

A library providing dynamic GraphQL object classes from their zod validation objects.

Overview

If you're diving into the world of GraphQL with NestJS, then integrating Zod for validation can significantly streamline your workflow. The nestjs-graphql-zod library simplifies the way you handle validation by allowing you to use Zod validation objects directly in your GraphQL actions, eliminating the overhead of writing GraphQL schema classes. This utility not only enhances your development experience but also improves code readability and maintainability.

With support for advanced features like nested objects and custom descriptions, this library promises a robust solution for creating GraphQL schemas. Whether you need to implement primitives or enums, you can do so seamlessly, ensuring your application’s data integrity with minimal effort.

Features

  • Zod Object Integration: Use Zod validation objects directly in GraphQL actions without creating separate schema classes, enhancing the overall efficiency of your code.

  • Nested Object Support: Easily handle nested Zod object calls, allowing automatic generation of separate GraphQL models for each nested definition.

  • Custom Model Naming: Provide custom names for GraphQL models using a specific format in descriptions, facilitating clear identification in your schema.

  • Enum Support: Effortlessly integrate Zod enums, with the library automatically generating enum models appropriate for your GraphQL schema.

  • Input and Output Validation: Utilize decorators like @QueryWithZod and @MutationWithZod for robust validation of both input and output data against Zod schemas.

  • Utility Functions: Access a range of utility functions such as modelFromZod and inputFromZod to dynamically create GraphQL ObjectTypes and InputTypes based on Zod inputs.

  • Custom Scalar Types: Define complex schemas with the ability to set custom GraphQL scalar types through the setDefaultTypeProvider function, enhancing compatibility with various data types.

  • Convenient Setup: Integrate the library into your NestJS project with a simple addition to your package.json, ensuring a hassle-free setup process.

nestjs
Nest

A progressive Node.js framework for building efficient, scalable, and enterprise-grade server-side applications with TypeScript/JavaScript.

graphql
Graphql

A website that uses GraphQL as a query language to manage data fetching and state management. This includes features such as a strongly typed schema, client-side caching, and declarative data fetching to streamline data management and optimize website performance.

typescript
Typescript

TypeScript is a superset of JavaScript, providing optional static typing, classes, interfaces, and other features that help developers write more maintainable and scalable code. TypeScript's static typing system can catch errors at compile-time, making it easier to build and maintain large applications.

zod
Zod

Zod is a TypeScript-first schema declaration and validation library. It allows you to define schemas that can validate data at runtime while providing excellent TypeScript inference, making it perfect for API validation, form validation, and type-safe data handling.