Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

console.log outputs incorrect value when result extensions are used #16554

Closed
SevInf opened this issue Nov 30, 2022 · 0 comments · Fixed by #16542
Closed

console.log outputs incorrect value when result extensions are used #16554

SevInf opened this issue Nov 30, 2022 · 0 comments · Fixed by #16542
Assignees
Labels
kind/bug A reported bug. team/client Issue for team Client. topic: clientExtensions
Milestone

Comments

@SevInf
Copy link
Contributor

SevInf commented Nov 30, 2022

This code

import { PrismaClient } from '@prisma/client'

const prisma = new PrismaClient().$extends({
  result: {
    user: {
      fullName: {
        needs: { firstName: true, lastName: true },
        compute(user) {
          return `${user.firstName} ${user.lastName}`
        }
      }
    }
  }
})


async function main() {
  await prisma.user.deleteMany()
  await prisma.user.create({
    data: {
      firstName: 'Boaty',
      lastName: 'McBoatface'
    }
  })

  const data = await prisma.user.findFirst({
    select: {
      fullName: true
    }
  })

  console.log(data)

}

main()
  .then(async () => {
    await prisma.$disconnect()
  })
  .catch(async (e) => {
    console.error(e)
    await prisma.$disconnect()
    process.exit(1)
  })

Outputs {firstName: 'Boaty', lastName: 'McBoatface' } which is incorrect. Expected result is and object with only fullName property.
However, this:

 console.log((data as any).firstName)
  console.log((data as any).lastName)
  console.log(data?.fullName)

Outputs:

undefined
undefined
Boaty McBoatface

So, the returned value is correct, just console.log displays it incorrectly.

@SevInf SevInf added kind/bug A reported bug. team/client Issue for team Client. topic: clientExtensions labels Nov 30, 2022
@millsp millsp added this to the 4.7.1 milestone Nov 30, 2022
@janpio janpio modified the milestones: 4.7.1, 4.8.0 Nov 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug A reported bug. team/client Issue for team Client. topic: clientExtensions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants