Tip - Serialization

A feature that is still being improved.

When discussing serialization, in the sense of altering the response returned (hide password, bring order's total), this is something that Prisma still does not excel, let's say. To achieve this currently is not trivial, some alternatives are:

  • Create an entity that reflects the model and uses class transformer decorators (code duplication)

  • Use an interceptor to analyse the response and alter it as necessary(bad performance)

But none of these is particularly ideal. Recently, Prisma has received a preview omit option when fetching entities. Still not ideal but at least it is a bit better. Does not cover all cases but we could use it in the findAll() and findOne() methods in the UsersService if this feature is enabled.

omit: {
  password: true
}

Ideally, this should be available at the schema level. Let's hope for an update from the Prisma team. According to them, this is being worked on right now.

Last updated