prisma / codemods

A Collection of Codemods for Prisma 2

Home Page:https://www.prisma.io/docs/guides/upgrade-guides/upgrading-versions/codemods

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

findUnique codemod does not work with variables names other than `prisma`

NMinhNguyen opened this issue · comments

Describe the bug

The codemod expects the Prisma client to be called prisma (

if("findOne" === idPath.value.name && (idPath?.parent?.value?.object?.object?.name === 'prisma' || idPath?.parent?.value?.object?.object?.property?.name === 'prisma')){
) and thus it doesn't apply transforms if your PrismaClient instance is called anything else, e.g. client. Ideally the codemod should trace the import and allow any variable name (identifier).

Before the codemod

import { PrismaClient } from '@prisma/client'

const client = new PrismaClient();

client.x.findOne({ where: { id: 'test' } });

After the codemod

import { PrismaClient } from '@prisma/client'

const client = new PrismaClient();

client.x.findOne({ where: { id: 'test' } });

Expected output

import { PrismaClient } from '@prisma/client'

const client = new PrismaClient();

client.x.findUnique({ where: { id: 'test' } });

Additional context
Add any other context about the problem here.

Hey folks, this should now be supported in 0.7.0.

I have also added the ability to pass in custom instance names (i.e --instanceNames=myClient)
This is helpful when importing already instantiated clients.

import myClient from './myClient'

Please reopen if you are still having issues after upgrading