J Giri
07/23/2021, 3:49 AMtypegraphql-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.
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
@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
@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 typesRyan
07/23/2021, 6:30 AM.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 Giri
07/23/2021, 6:38 AMJ Giri
07/23/2021, 6:41 AM.graphql
file too, the password field is not omitted.Ryan
07/23/2021, 6:43 AMJ Giri
07/23/2021, 6:47 AMpassword
is present as one the fields in register
mutation.
And while doing mutation the password is sent as a field.J Giri
07/23/2021, 6:47 AMRyan
07/23/2021, 6:49 AMRyan
07/23/2021, 6:49 AMJ Giri
07/23/2021, 6:52 AMJ Giri
07/23/2021, 7:09 AMJ Giri
07/23/2021, 7:11 AMRyan
07/23/2021, 7:31 AMprisma
and typegraphql
versions same as what’s in my project and then check?J Giri
07/23/2021, 7:41 AMmodel 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
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")
// }
Ryan
07/23/2021, 7:43 AMTypeGraphQL
in the comment 😅Ryan
07/23/2021, 7:44 AMJ Giri
07/23/2021, 7:47 AMJ Giri
07/23/2021, 7:50 AML
.
The source of mistake.