P
Prisma•6mo ago
mitchell

Console Spam: "CODE: PrismaClientOnContextInstanceOfStrategyFailed"

Hey guys, getting a constant spam of this error/warning:
CODE: PrismaClientOnContextInstanceOfStrategyFailed
WARNING: Prisma Client on GraphQL context failed being checked using instanceof
REASON: The Prisma Client class reference imported from @prisma/client is not the same class used by you to create your Prisma Client instance.
CONSEQUENCE: Maybe none since duck typing fallback indicates that the Prisma Client on the GraphQL context is actually valid. However relying on duck typing is hacky.
CODE: PrismaClientOnContextInstanceOfStrategyFailed
WARNING: Prisma Client on GraphQL context failed being checked using instanceof
REASON: The Prisma Client class reference imported from @prisma/client is not the same class used by you to create your Prisma Client instance.
CONSEQUENCE: Maybe none since duck typing fallback indicates that the Prisma Client on the GraphQL context is actually valid. However relying on duck typing is hacky.
Had it for a while and still can't figure out exactly what might cause it, the error message itself is going over my head a bit. I can understand it in a general sense, but not enough to know why it's popped up or what could be causing it. It specifically hits my console when a user is making a GQL query to our backend, which is using Nexus/Nexus-Prisma. Any ideas? Can't find any mention of this warning code anywhere. Prisma Version: 6.10.1 SOLUTION UPDATE: This was actually a warning from nexus-prisma, which can be changed/turned off using the runtime settings:
// You can put this code anywhere at runtime, I put it at our backend server entrypoint.

// These are the runtime settings for nexus-prisma, located wherever you generate your nexus-prisma code.
import { $settings } from "../prisma/generated/nexus-prisma";

$settings({
checks: {
PrismaClientOnContext: {
strategy: 'duckType'
}
}
});
// You can put this code anywhere at runtime, I put it at our backend server entrypoint.

// These are the runtime settings for nexus-prisma, located wherever you generate your nexus-prisma code.
import { $settings } from "../prisma/generated/nexus-prisma";

$settings({
checks: {
PrismaClientOnContext: {
strategy: 'duckType'
}
}
});
7 Replies
Prisma AI Help
Prisma AI Help•6mo ago
You're in no rush, so we'll let a dev step in. Enjoy your coffee, or drop into #ask-ai if you get antsy for a second opinion!
Nurul
Nurul•6mo ago
Do you have multiple PrismaClient instances in your app?
mitchell
mitchellOP•6mo ago
Sorry for the delay over the weekend - yes and no. We run multiple instances over PM2, but each application instance draws from the same client, as below:
// ./src/services/prisma/index.ts
const prisma = new PrismaClient();

export function usePrisma(): PrismaClient {
return prisma;
}

// rest of codebase
await usePrisma().user.findMany() (etc.)
// ./src/services/prisma/index.ts
const prisma = new PrismaClient();

export function usePrisma(): PrismaClient {
return prisma;
}

// rest of codebase
await usePrisma().user.findMany() (etc.)
We've been using Prisma without issues like this for years, I believe this has only come up since we updated from 5.22.0 to 6.10.1 last week.
Nurul
Nurul•6mo ago
I am not aware of any changes from version 5 to 6 that could have triggered this error. Maybe graphql-nexus team did some changes 🤔
mitchell
mitchellOP•6mo ago
From what I understand, graphql-nexus/prisma-nexus hasn't updated all year. Is there a way to potentially just mute the log? It's not causing me any issues besides flooding my production console every time someone sends a gql query. Looking deeper, the warning is coming directly from nexus-prisma and not prisma itself. Will have to keep researching, thank you! If anyone comes looking for this solution later, here is finally how I resolved it:
// These are the runtime settings for nexus-prisma, located wherever you generate your nexus-prisma code.
import { $settings } from "../prisma/generated/nexus-prisma";

$settings({
checks: {
PrismaClientOnContext: {
strategy: 'duckType'
}
}
});
// These are the runtime settings for nexus-prisma, located wherever you generate your nexus-prisma code.
import { $settings } from "../prisma/generated/nexus-prisma";

$settings({
checks: {
PrismaClientOnContext: {
strategy: 'duckType'
}
}
});
Nurul
Nurul•6mo ago
Thanks for taking the time to share the solution 🙌

Did you find this page helpful?