paljs / prisma-tools

Prisma tools to help you generate CRUD system for GraphQL servers
https://paljs.com
MIT License
683 stars 54 forks source link

PismaDelete.onDelete.returnFields throws Prisma error. #154

Closed ObserverMoment closed 3 years ago

ObserverMoment commented 3 years ago

Hi, thanks for the last quick update. Returnfields is a great idea but there seems to be an issue in that prisma.deleteMany() return a BatchPayload object rather than the original model, which only has one field on it - count.

const deletedUser: User = await prisma.onDelete({
    model: 'User',
    where: { id },
    deleteParent: true,
    returnFields: {
      id: true,
      imageUrl: true,
      videoUrl: true,
      videoThumbUrl: true,
    },
  })
[1] {
[1]   where: {
[1]     id: '7cbf009e-1241-4cde-85bf-aa62508c96da'
[1]   },
[1]   select: {
[1]     id: true,
[1]     ~~
[1]     imageUrl: true,
[1]     ~~~~~~~~
[1]     demoVideoUrl: true,
[1]     ~~~~~~~~~~~~
[1]     demoVideoThumbUrl: true,
[1]     ~~~~~~~~~~~~~~~~~
[1] ?   count?: true
[1]   }
[1] }
[1] Unknown field `id` for select statement on model BatchPayload. Available options are listed in green.
[1] Unknown field `imageUrl` for select statement on model BatchPayload. Available options are listed in green. Did you mean `count`?
[1] Unknown field `demoVideoUrl` for select statement on model BatchPayload. Available options are listed in green. Did you mean `count`?
[1] Unknown field `demoVideoThumbUrl` for select statement on model BatchPayload. Available options are listed in green.

Wondering if my syntax is wrong or if there is some other fix / update that would allow the functionality to work?

Perhaps switch the final return statement (when deleting the initial parent) to a standard prisma.delete()?

https://github.com/paljs/prisma-tools/blob/7b657d3c4b444dda58ca122f2cfdd0394bae6727/packages/plugins/src/delete.ts#L158

AhmedElywa commented 3 years ago

I can not check if the user tries to delete one or many, so many works with both. I think the right idea to make delete parent false, and you can delete the parent in your side is you can select what you need

ObserverMoment commented 3 years ago

I see, yeah that should work! Thanks will try that.