yoga graphql 服务器 + prisma 服务器:多租户
yoga graphql server + prisma server : multitenancy
我正在使用 Prisma Server 和 Yoga GraphQL 为多租户数据库设置后端环境
为了管理多租户,我们选择使用 Prisma Server 的“env”(dev/stage/prod) 来处理。
没关系,Prisma 服务器并不难管理,现在我们为每个租户都有一个端点,例如:http://localhost:4466/service/tenant/
之后,使用 graphql get-schema 很容易从 Prisma 中提取 *.graphql。
但是现在,困难是:如何为我需要的服务和租户设置 GraphQL 服务器?
基于不同的例子/tuto/docs/...我没有找到在我的 index.js 中设置 GraphQL 服务器的方法说:监听多个 URI,每个 URI 都有一个 prisma 服务器已连接。
例子,我需要:
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 似乎每个端口只能启动一次(这里是 4000)
[编辑] 这里有一个代码来说明 https://github.com/mouchimotte/prisma-yoga-multitenancy
正如@rma 在评论中所说,您可以使用 prisma-multi-tenant npm 包来构建多租户应用程序。
您可以阅读这篇解释如何使其工作的文章:https://medium.zenika.com/building-a-multi-tenant-application-with-prisma-11bf890304d6
如果您希望使用共享数据库策略,也就是说,一个带有租户 ID 列的数据库,您可以使用这个包:
https://www.npmjs.com/package/node-express-multitenant
我正在使用 Prisma Server 和 Yoga GraphQL 为多租户数据库设置后端环境
为了管理多租户,我们选择使用 Prisma Server 的“env”(dev/stage/prod) 来处理。
没关系,Prisma 服务器并不难管理,现在我们为每个租户都有一个端点,例如:http://localhost:4466/service/tenant/
之后,使用 graphql get-schema 很容易从 Prisma 中提取 *.graphql。
但是现在,困难是:如何为我需要的服务和租户设置 GraphQL 服务器?
基于不同的例子/tuto/docs/...我没有找到在我的 index.js 中设置 GraphQL 服务器的方法说:监听多个 URI,每个 URI 都有一个 prisma 服务器已连接。
例子,我需要:
GraphQL Server endpoint
http://localhost:4000/service-1/client-1/
can be only requesthttp://localhost:4466/service-1/client-1/
and for
client-2
(second tenant)http://localhost:4000/service-1/client-2/
can be only requesthttp://localhost:4466/service-1/client-2/
GraphQL Server 似乎每个端口只能启动一次(这里是 4000)
[编辑] 这里有一个代码来说明 https://github.com/mouchimotte/prisma-yoga-multitenancy
正如@rma 在评论中所说,您可以使用 prisma-multi-tenant npm 包来构建多租户应用程序。
您可以阅读这篇解释如何使其工作的文章:https://medium.zenika.com/building-a-multi-tenant-application-with-prisma-11bf890304d6
如果您希望使用共享数据库策略,也就是说,一个带有租户 ID 列的数据库,您可以使用这个包: https://www.npmjs.com/package/node-express-multitenant