graphql-nexus / nexus-plugin-prisma

Deprecated
MIT License
829 stars 118 forks source link

Nexus with Prisma 2 doesn't support Multiple DB Connections #992

Open fullStackDataSolutions opened 3 years ago

fullStackDataSolutions commented 3 years ago

I was able to connect to multiple DBs with Prisma 1 and Nexus, but just creating multiple clients and then merging them all into the schema, however I haven't figure out a way to do this with Prisma 2 and Nexus.

This is a huge issue for how my company is using Nexus. Has anyone figured out a work around for this?

PerfectedApp commented 3 years ago

This issue is related to another: #835

The parameter config for prismaClient only supports one client. Value expected is a string. See here: https://github.com/graphql-nexus/nexus-plugin-prisma/blob/main/src/typegen/render.ts#L11

The render of index.d.ts in @ types>typegen-nexus-plugin-prisma has only support for one client: https://github.com/graphql-nexus/nexus-plugin-prisma/blob/main/src/typegen/render.ts#L56

Those items above, I think, would be somewhat easy to support, but the problem I see is how we would know which Prisma client to use for which model? As far as I see in the nexus:src/definitions/objectType.ts -- there's not much work with for existing code. I doubt main owners of nexus core would want to update this just for Prisma Plugin.

We could have another config param that is part of prismaClient where we state types as a child array of each prisma clients. Not sure this is good. If two or more clients have the same model name?

PerfectedApp commented 3 years ago

A smelly solution could be the hijacking of description param in objectType with some sort of meta syntax to state which client to use.

fullStackDataSolutions commented 3 years ago

Seems like you could just wrap all the Types in different client names. Or append something to the front of of each type to mach the DB name.

There's many solutions.

I am now using multiple clients through merge schema.

PerfectedApp commented 3 years ago

How does merged schema work with different db contexts?

fullStackDataSolutions commented 3 years ago

I'm using the Nexus-Prisma-Plugin, that outputs a schema, so I then create a second file structure with the second client and merge them together. I think it would be better to combine in one client, but it works.

My only questions is whether or not I will be able to connect two different DBs together where relationships exist and I will find that out shortly.

I can't share the code, but if you want to document it for other to use I could show you what I did and probably make a simple version to share some time in the future.

PerfectedApp commented 3 years ago

Don't you lose the type-sense without using the types>typegen-nexus-plugin-prisma output in node_modules? The whole idea of nexus using t.model.param is tied to this as I understand it.

fullStackDataSolutions commented 3 years ago

No, it all works, you just have a file for each client that outputs all the generated types. It's pretty hard to explain without a code example. I will see if I can can put something together.