question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multiple prisma clients - many databases

See original GitHub issue

In code

export function getPrismaFromContext(context: any) {
  const prismaClient = context.prisma;
  if (!prismaClient) {
    throw new Error("Unable to find Prisma Client in GraphQL context. Please provide it under the `context.prisma` key.");
  }
  return prismaClient;
}

there is a fixed “prisma” key, but If we would add parametrization of this name in the config, then we would be able to use it with many databases that have their own clients in context.

Probably we need extend this cod by new option with default value “prisma”:

export interface ExternalGeneratorOptions {
  emitDMMF?: boolean;
  emitTranspiledCode?: boolean;
  simpleResolvers?: boolean;
  useOriginalMapping?: boolean;
  useUncheckedScalarInputs?: boolean;
  emitIdAsIDType?: boolean;
  emitOnly?: EmitBlockKind[];
  customPrismaImportPath?: string;
}

then add this param to function generateHelpersFile and replace “prisma” by this parameter in

    export function getPrismaFromContext(context: any) {
      const prismaClient = context.prisma;
      if (!prismaClient) {
        throw new Error("Unable to find Prisma Client in GraphQL context. Please provide it under the `context.prisma` key.");
      }
      return prismaClient;
    }

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:16 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
viis233commented, Aug 19, 2022

I modified the generator and it seems to be working fine. I don’t know if there is a hidden problem. image

1reaction
MichalLytekcommented, May 9, 2022

Conflict between declared prisma context key and runtime prisma clients in graphql context

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use Prisma with multiple database schemas
Many database providers allow you to organize database tables into named groups. ... query across multiple database schemas with Prisma Client ...
Read more >
Multiple Connections / Databases / Datasources #2443 - GitHub
I'm using multiple schema files in production right now for many projects. Prisma client works fine, you just import from wherever you set...
Read more >
I want to use multiple database in prisma orm - Stack Overflow
prisma in separate folders and initialise PrismaClient for each schema.prisma that will point to the specific database. Share.
Read more >
Multiple Prisma Clients, One App - zach.codes
Multiple Prisma Clients, One App. There are times where you need to connect to multiple databases within a single backend server.
Read more >
How to connect Multiple Databases using Prisma in Nest JS
You can use multiple databases with Prisma by creating different schema files and generating separate Prisma clients for each database. References: github link ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found