J Giri
07/02/2021, 7:23 AMtypegraphql-prisma . I have my types generated using typegraphql-prisma. In one of the resolver I made, in it I used User type (created by typegraphql-prisma).
@Mutation(() => User)
async register(
@Arg("firstName") firstName: string,
@Arg("lastName") lastName: string,
@Arg("email") email: string,
@Arg("password") password: string
): Promise<User> {
const hashedPassword = await bcrypt.hash(password, 12);
const user = await prisma.user.create({
data: {
firstName,
lastName,
email,
password: hashedPassword,
},
});
The problem is there is also a field for password (as expected return property) in User type definiation (created by typegraphql-prisma) like below.
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.Field(_type => String, {
nullable: false
})
password!: string;
}
I dont want the password field as the property in the returned User type.
Even if i omit the password field manually, npx generate regenerate the types and again password field is there.
How to work around this?Ryan
07/02/2021, 7:25 AMJ Giri
07/02/2021, 7:36 AMTypeGraphQL makes developing GraphQL APIs an enjoyable process, i.e. by defining the schema using only classes and a bit of decorator magic.
So, to create types like object type or input type, we use a kind of DTO classes. For example, to declaretype we simply create a class and annotate it with decorators:Recipe
@ObjectType()
class Recipe {
@Field(type => ID)
id: string;
@Field()
title: string;
@Field(type => [Rate])
ratings: Rate[];
@Field({ nullable: true })
averageRating?: number;
}
And we get the corresponding part of the schema in SDL:
type Recipe {
id: ID!
title: String!
ratings: [Rate!]!
averageRating: Float
This statement "And we get the corresponding part of the schema in SDL". Where do i find the corresponding schema in SDL? I have had to use}
typegraphql-prisma explicitly to get this. How can i get it automatically?Ryan
07/02/2021, 7:48 AMJ Giri
07/02/2021, 7:53 AMJ Giri
07/02/2021, 10:08 AMRyan
07/02/2021, 10:13 AMschema.graphql generated that you can view. This GraphQL file is the main file used by your server and the definitions what you see in the GraphQL Playground.