3
votes

I'm setting up a backend env for multi-tenancy database using Prisma Server and Yoga GraphQL

To manage multi-tenancy, we choose to handle it by using the "env" (dev/stage/prod) of Prisma Server. It's OK, Prisma server was not difficult to manage and now we have an endpoint for each tenant like: http://localhost:4466/service/tenant/

After that, it was easy to extract *.graphql from Prisma using graphql get-schema.

But now, the difficulty is: how to set up a GraphQL Server for as many as service I need and tenant ?

Based on different exmample / tuto / docs / ... I don't find the way to set up GraphQL Server in my index.js to say: listen on multiple URI and each URI have one prisma server connected.

Example, I need:

GraphQL Server endpoint http://localhost:4000/service-1/client-1/ can be only request http://localhost:4466/service-1/client-1/

and for client-2 (second tenant) http://localhost:4000/service-1/client-2/ can be only request http://localhost:4466/service-1/client-2/

GraphQL Server seems can be started only one time per port (here 4000)

[EDIT] Here a code to illustrate https://github.com/mouchimotte/prisma-yoga-multitenancy

1
If you need more details do not hesitate ;) - mouchi motte
I have just found this library (npmjs.com/package/prisma-multi-tenant). I hope it helps - rma
thanks a lot @rma ! I think this package can be ma solution but I've stop dev using Prisma. I use Laravel instead, surely more longer to have the first query operational but more easy and structured ! More in adequateness with my product finally - mouchi motte

1 Answers

0
votes

As @rma said in a comment, you can use the prisma-multi-tenant npm package to build a multi-tenant application.

You can read this article which explains how to make it work: https://medium.zenika.com/building-a-multi-tenant-application-with-prisma-11bf890304d6