'yoga graphql server + prisma server : multitenancy

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



Solution 1:[1]

If you wish to use a shared database strategy, meaning, one database with tenant ID column, you can use this package: https://www.npmjs.com/package/node-express-multitenant

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Shaul Zuarets