我一直在使用 Prisma 自学 GraphQL —— 两者都是初学者。
我刚刚进行了一个编程测试,其简介是将 React Native 前端连接到 WordPress 后端。我认为这可能是一个将 Prisma 和 GraphQL 付诸实践的有趣机会。我的想法是将 Prisma 连接到 WP MySQL DB,然后使用 Prisma-GraphQL 连接到 React Native。
然而,将 Prisma 连接到 MySQL 似乎并不是那么简单——至少对于我这个初学者来说是这样。我欢迎任何关于如何解决这个问题的信息——当然不是详细的代码,而是更多地了解我正在考虑的事情是否合理,以及什么包/路线将是最好的前进方式。谢谢!
最佳答案
一个简单的答案是:将 Prisma 连接到任何 MySQL 数据库所需的只是一个主机和一个数据库所在的端口(3306,因为这是 MYSQL)正在运行。
这让我们知道您的 Prisma 服务器在哪里运行?
如果你只是一个前端开发人员,并且你不知道或不想处理像 docker 这样的东西,那么你最好使用类似 Prisma Cloud 的东西。它将为您配置 Prisma 服务器,还可以为您托管 MySQL 数据库,或者您可以自己托管它并选择现有数据库选项并提供您在创建 Prisma 服务器期间拥有的主机名 (URL)。
另一方面,如果您愿意在本地或使用 Docker ( Local Prisma Setup ) 在云提供商上运行它,那么您只需提供主机和端口,如您在 docker-compose 配置文件中上面的文档链接中看到的那样到棱镜。
update: Regard connecting to an existing DB, If you tried to do a
prisma deploy
on a DB with a different schema it probably gonna blow and complain about the schema conflict, that's why you need introspection for before but as you mentioned in the comment it's only for PostgreSQL at the moment, they are working on creating a tool for MySQL but it's no one knows when it could be out you can check for updates on the open issue with this feature here
希望这可以帮助简化一些事情。
关于mysql - 如何将 Prisma/GraphQL 连接到现有的 MySQL 数据库(特别是 WordPress)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55067290/