Alex Freire Spinola

02/13/2019, 12:42 AM
Guys at my work we have a php lumen REST API. It uses two databases MySQL and Mongo it is possible to use Prisma to interface with 2 databases?
I am planning to rewrite this API using graphql as a first usage of graphql at my job
Do you guys have any tips to start?


02/13/2019, 5:20 AM
To my understanding, it is possible to create a Prisma schema which spans multiple databases however that particular feature is in closed beta (or will soon be). The feature is spec'ed out to be included in what has been dubbed
Datamodel v2
. @marcus invited folks to contact him if they wished to participate in that trial in this issue: https://github.com/prisma/prisma/issues/3405#issuecomment-456323909
If you want to stick to the beaten path, you might consider simply setting up two separate Prisma services, one per database. The main drawback to this approach is that you cannot host the two services on the same Prisma Server instance, as each Prisma Server (in its stable iteration -- dunno' what the Datamodel v2 changes look like!) allows for only a single database. So, you would need two instances of Prisma Server.
If you have the two instances set up, you can provide a single "public" schema which unifies the two "private" Prisma servers. The trick from there would simply be writing resolvers which make requests using two different Prisma Clients (see my answer to @Benoit Ranque just below this thread for more detail on configuring the two Clients) and properly combine the two databases' contents.