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

exclude column form selection (Hidden Columns) @select(false) #3636

Closed
satishbabariya opened this issue Apr 12, 2020 · 10 comments
Closed

exclude column form selection (Hidden Columns) @select(false) #3636

satishbabariya opened this issue Apr 12, 2020 · 10 comments
Labels
kind/feature A request for a new feature. team/client Issue for team Client. topic: prisma-client topic: schema

Comments

@satishbabariya
Copy link

Problem

How can i exclude certain column form select query overall like Password in the User Model.

Currently i'm using @Column({ select: false }) in typeorm.
ref: https://github.com/satishbabariya/nodejs-boilerplate/blob/master/src/models/User.ts#L37

Is ther any way to do this in prisma2? like

model User {
  id       Int    @default(autoincrement()) @id
  email    String @unique
  password String @select(false)
}

reference of TypeORM: https://typeorm.io/#/select-query-builder/hidden-columns

@pantharshit00
Copy link
Contributor

@schickling schickling transferred this issue from prisma/prisma Apr 21, 2020
@schickling
Copy link
Member

@un33k
Copy link

un33k commented Apr 21, 2021

@satishbabariya Thank you for raising this ticket.

For now I have to omit them painstakingly like

export type UserWhereInput = Omit<Prisma.UserWhereInput, 'password' | 'isActive'>;

Note that password and isActive have lost types here in the above line. :(

Looking forward to this feature available with the preview flag.

@janpio janpio added the team/client Issue for team Client. label Apr 22, 2021
@suprim12

This comment has been minimized.

@akomm
Copy link

akomm commented Jul 18, 2021

I can't express how important this feature is

@benbender
Copy link

@satishbabariya Thank you for raising this ticket.

For now I have to omit them painstakingly like

export type UserWhereInput = Omit<Prisma.UserWhereInput, 'password' | 'isActive'>;

You are only omit the typing for those fields and not the actual fields in the select or result. So those fields would be, for example, still included in an API-Response. Or am I missing something here?

@akomm
Copy link

akomm commented Sep 1, 2021

This is especially dangerous because basically any manipulation, even deletion, in prisma is returning the complete selection of all fields.

The moment you just think for a second writing your code, you stumble uppon this. I try to wrap my head around how this behavior, without any options to change it, could make it into a release and be ignored for so long.

@un33k
Copy link

un33k commented Sep 7, 2021

@benbender your are correct. The following is only enforcing the shape of the desired data.

export type UserWhereInput = Omit<Prisma.UserWhereInput, 'password' | 'isActive'>;

In turn, the data type is handed over to class-validator & graphql types to ensure validations on the way in / out.

Since Prisma cannot (at this time) exclude fields out-of-the-box, some acrobatic steps are performed to achieve a secure API.

This is an example that does the job well for now - It will be removed once Prisma provides some intuitive exclude rules.

@hgezim
Copy link

hgezim commented Oct 14, 2021

I'm also interested in having this solved.

@matthewmueller
Copy link
Contributor

Closing in favor of #5042. We'll provide one solution for this whether it's in the schema or within the query is TBD.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature A request for a new feature. team/client Issue for team Client. topic: prisma-client topic: schema
Projects
None yet
Development

No branches or pull requests

10 participants