-
-
Notifications
You must be signed in to change notification settings - Fork 106
[Feature Request] ZenStack for API integration #563
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi @ymc9, and thank you for this RFC. If I understand correctly, these plugins (clerk, blob, stripe...) would be built-in to Zenstack (non-customizable)? Initially, I was thinking of a more extensible system where we can write the desired logic, with the plugin providing access to model fields and abstracting other fields if needed (abstract models). It would be a kind of wrapper for Prisma's
await prisma.user.update({ // --> not sure about that...
where: { id },
data: { profileImage: { file, bucket, path } } }
});
const user = await prisma.user.findUnique({
where: { id }
});
const imageUrl = await user.profileImage; In any case, I find the plugin system very useful, and the proposed syntax very clear. |
Hi @Azzerty23 , thanks for the comment and example. My apologies for not being clear in the initial draft. The plugins are supposed to be implemented outside of ZenStack, and hopefully, many of them by the community. You can think of the "provider" of the plugin to be all independent and standalone NPM packages. In fact, most of today's plugins, like If we were to go in this direction, ZenStack's core would define a richer contact for the plugins, like how to contribute models (as shown in your example with the I haven't thought much about if this should be implemented based on Prisma's client extensions. It's definitely worth a try, just not sure if we'll soon hit some limit there. |
Not sure if is worth a look, but Supabase is creating something similar this from a database perspective here https://supabase.github.io/wrappers/stripe/ The wrapper expose data through the database as a plugin.... It would be really COOL to have a ZenSack plugin that added/synced with those data models. So i could query through my prisma client. For me... i really only want to generate them in the client and ignore them in any "migrations", I think it would be great if we expose client queries to tables we don't OWN. This might not be important but maybe a consideration of what this plugins can do. |
Thanks for the pointer @bvkimball ! I didn't know Supabase has a set of Postgres FDW. They can be very good references. Yes, indeed the idea is quite close to FDW, just work at a higher level. The foreign models won't be mapped to the database so shouldn't affect migration. The only trace they'll leave on the database is when you create a relation from a real model to a foreign model, on the real model side there should be a "virtual" foreign key that's persisted into the db. |
Very interesting. I just wonder if defining the plugins on the schema itself would later become a limitation in terms of adding custom logic to the plugin functions / helpers. |
Hi @pedrosimao , the plugins are just declared in the schema, and their implementation will be made in TS/JS. |
One question I do have: Let’s say I plan to use Lemonsqueezy as a payments/billing service instead of Stripe, and the Zenstack library doesn’t have a first-party plugin for that, but only for Stripe. How easy would it be to create our own custom plugins to wrap any external API we wish? |
Hi @andrictham , the idea is to make API integration part of the plugin mechanism, so that developers can introduce new integrations without changing the core. The detailed design hasn't been made yet. |
NOTE: This is quite ambitious item, and chance is low it can be contained in V2, but including it here just for people who may find it very useful and want to give it a push
The proposal here is based on previous discussions with people on Discord. Moving to GitHub for better visibility.
Goal
Prisma’s schema offers a pleasant DX to model and program against a database. However, the pattern - DSL schema + TS code generation, has more potential than working with databases. Since ZenStack has already replicated the entire Prisma schema language with many extensions, we can try to achieve more above that.
Web development has been gradually shifting from hosting everything in-house to leveraging external services. That means databases, as important as they still are, only represent a (shrinking) part of the entire application’s model. Databases often store “opaque references” to models of foreign systems, and developers have to deal with disparate APIs and orchestrate them with database operations.
Hopefully, we can make the schema a gateway toward unifying and simplifying the DX:
ZenStack should provide a more powerful plugin mechanism, allowing plugin developers to contribute models and runtime behavior to interface with 3rd-party API systems.
Use Cases
1. Auth
When using auth services like Clerk, the main user repository is on the auth provider’s side. If you don’t choose to synchronize it to your own database, you can reference it as a foreign model:
And the enhanced PrismaClient allows you to do things like:
2. Blob Data
Using blob services like S3 to store files and save a reference in database table is a very common pattern.
3. Subscription
Interfacing with payment systems like Stripe:
Potential Approach
Open Questions
Related
Supabase FDW
The text was updated successfully, but these errors were encountered: