我正在使用Prisma Server和Yoga GraphQL为多租户数据库设置后端环境
为了管理多租户,我们选择使用Prisma Server的"env"(dev / stage / prod)来处理它 . 没关系,Prisma服务器不难管理,现在我们为每个租户设置了一个 endpoints ,如: http://localhost:4466/service/tenant/
之后,很容易使用graphql get-schema从Prisma中提取* .graphql .
但现在,困难在于:如何为我需要的服务和租户设置GraphQL服务器?
基于不同的exmample / tuto / docs / ...我没有找到在我的index.js中设置GraphQL Server的方法来说:监听多个URI并且每个URI都连接了一个prisma服务器 .
例如,我需要:
GraphQL Server endpoints http:// localhost:4000 / service-1 / client-1 /只能请求http:// localhost:4466 / service-1 / client-1 /和client-2(第二个租户)http :// localhost:4000 / service-1 / client-2 /只能请求http:// localhost:4466 / service-1 / client-2 /
GraphQL Server似乎每个端口只能启动一次(此处为4000)
[编辑]这里有一个代码来说明https://github.com/mouchimotte/prisma-yoga-multitenancy
1 回答
正如@rma在评论中所说,您可以使用prisma-multi-tenant npm包来构建多租户应用程序 .
您可以阅读本文解释如何使其工作:https://medium.zenika.com/building-a-multi-tenant-application-with-prisma-11bf890304d6