'Typegoose, graphql, how to update fields with object types

I have a user schema:

@ObjectType()
export class User {
  @Field(() => String)
  _id: string;

  @Field(() => String)
  @prop({ required: true })
  userName: string;

  @Field(() => UserType)
  @prop({ enum: UserType })
  userType: UserType;

  @Field(() => String)
  @prop({ required: true })
  email: string;

  @prop({ required: true })
  password: string;

  @Field(() => Employee)
  @prop({ required: false })
  employee: Employee;

  @Field(() => Employer)
  @prop({ required: false })
  employer: Employer;
}

and the employee field has this schema:

@ObjectType()
class Employee {
  @Field(() => String)
  firstName: string;

  @Field(() => String)
  middleName: string;

  @Field(() => String)
  lastName: string;

  @Field(() => String)
  birthday: string;

  @Field(() => String)
  address1: string;

  @Field(() => String)
  address2: string;

  @Field(() => String)
  phoneNumber: string;

  @Field(() => String)
  emailAddress: string;

  @Field(() => String)
  socialMedia: string;

  @Field(() => String)
  imageLink: string;

  @Field(() => [WorkExperiences])
  workExperiences: WorkExperiences[];

  @Field(() => Personality)
  personality: Personality;

  @Field(() => Direction)
  direction: Direction;

  @Field(() => [Education])
  education: Education[];

  @Field(() => [Certificates])
  certificates: Certificates[];

  @Field(() => [Awards])
  awards: Awards[];

  @Field(() => String)
  applications: string;
}

I want to create a login form which only adds email and username then redirect to a onboarding page.

I am trying to create a separate mutations with Education, workExperience and other stuffs.

But I am not sure what I am doing.

What I did so far was to create a resolver for example education:

 @Authorized()
  @Mutation(() => User)
  createEducation(
    @Arg("input") input: CreateEducationInput,
    @Ctx() context: Context
  ) {
    const user = context.user!;
    return this.qualificationService.createEducation({
      ...input,
      user: user?._id,
    });
  }

But I can't seem to create education and throws some error.

I am not sure if I am doing this correctly. Really need help. Thanks guys!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source