zenstackhq / zenstack

Fullstack TypeScript toolkit that enhances Prisma ORM with flexible Authorization layer for RBAC/ABAC/PBAC/ReBAC, offering auto-generated type-safe APIs and frontend hooks.
https://zenstack.dev
MIT License
2.03k stars 85 forks source link

[Feature Request] Generate test mocks / DB seeds #772

Open olehmelnyk opened 11 months ago

olehmelnyk commented 11 months ago

Is your feature request related to a problem? Please describe. Generate test mocks / DB seeds based on schema/zod with some mapping (names, emails, images, dates, etc.) + using libs like fakerjs

ymc9 commented 11 months ago

Hi @olehmelnyk , it's a great idea. Right now, the focus of ZenStack is still on the core runtime and integrations with major frameworks, but I do see this as a great match for a community-contributed plugin. Something you'll be interested to work in?

jasonmacdonald commented 10 months ago

I'm currently looking into this same concept in conjunction with replacing our current class generation plugin prisma-nestjs-graphql as the original author appears to have other priorities, and it's not receiving updates.

I want to do this as a plugin that can be used directly with Prisma, but also as a Zenstack plugin that would provide additional QOL features on top of the base. I can't make any promises or guarantees, but I'll try to post here with any progress when available.

ymc9 commented 10 months ago

I'm currently looking into this same concept in conjunction with replacing our current class generation plugin prisma-nestjs-graphql as the original author appears to have other priorities, and it's not receiving updates.

I want to do this as a plugin that can be used directly with Prisma, but also as a Zenstack plugin that would provide additional QOL features on top of the base. I can't make any promises or guarantees, but I'll try to post here with any progress when available.

Awesome! In that case I guess it'll first be a Prisma generator and then wrapped into a ZenStack plugin (plugins include a Prisma "dmmf" object as input argument).

@jiashengguo recently made a standalone plugin here: https://github.com/jiashengguo/zenstack-markdown. It can be a good reference for getting started. I'm also working on the plugin writing part in the new "the complete guide" docs. Hopefully, it can be done in a day or two.

Let us know if you need any support!

Btw, what is QOL?

jasonmacdonald commented 10 months ago

Awesome! In that case I guess it'll first be a Prisma generator and then wrapped into a ZenStack plugin (plugins include a Prisma "dmmf" object as input argument).

That is the idea, but we'll see how it goes—lots of DMMF parsing to do.

Btw, what is QOL?

Quality Of Life :) Basically, it would improve the developer experience using Zenstack over the base Prisma plugin implementation.

jasonmacdonald commented 10 months ago

My idea is to create a more generic Class generator that can itself utilize plugins that visit different parts of the class before and during creation. These visitors could then add additional functionality, like adding @decorators for use with Graphql/ REST, or add additional methods like static generateTestModel() or static generateSeedMode() that could be used to generate seeding or testing data.

The problem I see right now on Prisma's generator page is everyone is reinventing the parsing/generation code for each plugin, which I think is a big barrier for others who have needs/ideas but don't want to take on the task. It's too bad Prisma doesn't provide this functionality, but at least we have the DMMF to do it ourselves.

I think if there was a class generator plugin that could then be enhanced by passing in "third-party" enhancers, it could give people an opportunity to do a lot of great stuff without needing to reinvent the wheel.

ymc9 commented 10 months ago

My idea is to create a more generic Class generator that can itself utilize plugins that visit different parts of the class before and during creation. These visitors could then add additional functionality, like adding @decorators for use with Graphql/ REST, or add additional methods like static generateTestModel() or static generateSeedMode() that could be used to generate seeding or testing data.

The problem I see right now on Prisma's generator page is everyone is reinventing the parsing/generation code for each plugin, which I think is a big barrier for others who have needs/ideas but don't want to take on the task. It's too bad Prisma doesn't provide this functionality, but at least we have the DMMF to do it ourselves.

I think if there was a class generator plugin that could then be enhanced by passing in "third-party" enhancers, it could give people an opportunity to do a lot of great stuff without needing to reinvent the wheel.

Got it. I hope the ZModel AST simplifies the job a bit. The DMMF object model is undocumented and pretty nasty to work with ... but when it comes to dealing with all the detailed types generated by Prisma, that's the only source. Yes, a reusable abstraction layer could be very beneficial. Every Prisma generator starts from scratch today, and I think there's a lot of copy-pasting around 😄.

Good luck with the endeavor, and looking forward to seeing the result!