There is a `typegraphql-prisma` issue which i face...
# orm-help
j
There is a
typegraphql-prisma
issue which i face most often. The feature of "hiding prisma model field in graphql schema" doesnt work most of the time. Presently also its not working As per doc I implemented
/// @TypeGraphQl.omit(output: true
to hide the password field in graphql Schema.
Copy code
model User {
  id        String @id @default(cuid()) @map("_id")
  firstName String @map("first_name")
  lastName  String @map("last_name")
  email     String @unique
  /// @TypeGraphQl.omit(output: true)
  password  String

  @@map("user")
}
IN GENERATED TYPES, EXPECTED RESULT SHOULD BE
Copy code
@TypeGraphQL.ObjectType({
  isAbstract: true
})
export class User {
  @TypeGraphQL.Field(_type => String, {
    nullable: false
  })
  id!: string;

  @TypeGraphQL.Field(_type => String, {
    nullable: false
  })
  firstName!: string;

  @TypeGraphQL.Field(_type => String, {
    nullable: false
  })
  lastName!: string;

  @TypeGraphQL.Field(_type => String, {
    nullable: false
  })
  email!: string;

  password?: string;
}
BUT WHAT I GET IN GENERATED TYPES IS
Copy code
@TypeGraphQL.ObjectType({
  isAbstract: true
})
export class User {
  @TypeGraphQL.Field(_type => String, {
    nullable: false
  })
  id!: string;

  @TypeGraphQL.Field(_type => String, {
    nullable: false
  })
  firstName!: string;

  @TypeGraphQL.Field(_type => String, {
    nullable: false
  })
  lastName!: string;

  @TypeGraphQL.Field(_type => String, {
    nullable: false
  })
  email!: string;

  /** @TypeGraphQl.omit(output: true) */
  @TypeGraphQL.Field(_type => String, {
    nullable: false,
    description: "@TypeGraphQl.omit(output: true)"
  })
  password!: string;
}
What I get in my unexpected result is not hiding graphql schema field. What am i getting unexpected result? In the past very few times i got expected generated types. Most often if emits the unexpected output, which is mentioned above, in generated types
r
@J Giri You need to check the final generated
.graphql
file and not the TypeGraphQL model: The place where this file is emitted will show you the
password
is omitted from the
User
type.
j
Ok i'm generating the schema SDL via typegraphql and letting u know. But as a matter of fact, when it was working in that rare times, the typegraphql model was as showing in "Expected result". I'm checking .schema file now
As expected, in the
.graphql
file too, the password field is not omitted.
r
Cannot reproduce. Here’s the setup:
j
Also in graphql api playground.
password
is present as one the fields in
register
mutation. And while doing mutation the password is sent as a field.
checking the zip.file. Letting u know soon
r
This will only affect the model. Not mutations.
j
I can see in ur project the typegraphql model is as expected as i mentioned in the main question. I also had very few times in the past like this. And also while doing mutation the password is not retured. Worked perfectly. Im regenerating the typegraphql models and schema SDL file and checking..
I checked it out. Your project is working as expected. Everything in the file is expected. But I'm also folowing with no mistake but i m not gettting the result with no error (previously i was getting). Might it have to do with version. As i can see lot of ur setup modules is not much uptodate. Could u please checkout my setup (its complete basic and fresh start with only one user model). ?
my setup modules is all completely uptodate. I m doing everything correctly as i use to do (when i was getting expected result like yours). It's not working lately. lately there was many update to serveral modules.
r
Could you keep
prisma
and
typegraphql
versions same as what’s in my project and then check?
j
I was able to narrow it down. I got it working back again by copy pasting my
model User {...
of
schema.prisma
from my previous project. Its working now. But there is last one thing i couldn't figure out. The code of
model User..
of the present one (which is not omitting the password field) and the one from previous project which i copy pasted in present and made it working, both are same. Could u figure out any difference from the two verision? Both are same but produce different result in the context of omitting ( one reflecting correctly in both typegrphql generated model and graphql playground api, while another is not reflecting) ? I'm super confused
Copy code
datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

generator client {
  provider = "prisma-client-js"
}

generator typegraphql {
  provider = "typegraphql-prisma"
  output   = "../src/types/generated/typegraphql-prisma"
}

//Right (from previous project)
model User {
  id        String @id @default(cuid()) @map("_id")
  firstName String @map("first_name")
  lastName  String @map("last_name")
  email     String @unique
  ///@TypeGraphQL.omit(output: true)
  password  String

  @@map("user")
}

//Wrong (present)
// model User {
//   id        String @id @default(cuid()) @map("_id")
//   firstName String @map("first_name")
//   lastName  String @map("last_name")
//   email     String @unique
//   ///@TypeGraphQl.omit(output: true)
//   password  String

//   @@map("user")
// }
r
There’s a difference in the spelling of
TypeGraphQL
in the comment 😅
Which is why it wasn’t working.
j
Oh shit shit shit. I knew it would be something very silly if there is any error from my end. I even checked by highlighting and everything was showing same. Vscode highlight doesn't differenciate between casing. Thank you so much. Turns out it was such a terrible lame mistake. Apology 🙂
🙌 1
This seems right casing of "l". The font of `l`in dracula theme of vscode seems like uppercase
L
. The source of mistake.
💯 1