Caught in a issue with `typegraphql-prisma` . I ha...
# orm-help
j
Caught in a issue with
typegraphql-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).
Copy code
@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.
Copy code
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?
j
In the doc you mentioned, i didnt understand one part.
TypeGraphQL 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 declare 
Recipe
 type we simply create a class and annotate it with decorators:
@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?
r
Where’s this exactly?
j
Shit! I'm so so sorry. I mistakenly read typegraphql doc https://github.com/MichalLytek/type-graphql. But this made me curious now. What is that mentioned about "getting corresponding part of schema SDL"? Can we get automated SDL out of the box like shown in doc?
My issue is solved now. Thanks for your reference. I'm new in this context. So pardon me being so naive
👍 1
r
SDL is just the
schema.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.