Skip to content

Update Typegoose dependency #552

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
alvaaz opened this issue Feb 27, 2020 · 2 comments
Closed

Update Typegoose dependency #552

alvaaz opened this issue Feb 27, 2020 · 2 comments
Labels
Community 👨‍👧 Something initiated by a community Documentation 📖 Issues about docs Solved ✔️ The issue has been solved

Comments

@alvaaz
Copy link

alvaaz commented Feb 27, 2020

Describe the issue
The example used in this repository for Typegoose use a deprecated package. The correct dependency is @typegoose/typegoose. When I updated it shows me an error:

Error output

[Node] (node:12838) UnhandledPromiseRejectionWarning: Error: Error: Generating schema error

My entity is

import { prop as Property, getModelForClass } from '@typegoose/typegoose'
import { ObjectId } from 'mongodb'
import { Field, ObjectType } from 'type-graphql'

@ObjectType()
export class Professional {
  @Field()
  readonly _id: ObjectId

  @Field()
  @Property({ required: true })
  firstName: string

  @Field()
  @Property({ required: true })
  lastName: string
}

export const ProfessionalModel = getModelForClass(Professional)

My resolver is

import { Resolver, Mutation, Arg } from 'type-graphql'
import { Professional, ProfessionalModel } from '../entities/Professional'

@InputType()
export class ProfessionalInput implements Partial<Professional> {
  @Field()
  firstName: string

  @Field()
  lastName: string
}

@Resolver()
export class ProfessionalResolver {
  @Mutation(() => Professional)
  async createProfessional(@Arg('options') options: ProfessionalInput): Promise<Professional> {
    try {
      const professional = new ProfessionalModel(options as Professional)

      return await professional.save()
    } catch (err) {
      console.log('Erroooooor', err)
    }
  }
}
@MichalLytek
Copy link
Owner

Fixed via 48cc1a9 🔒

@MichalLytek MichalLytek added Community 👨‍👧 Something initiated by a community Documentation 📖 Issues about docs Solved ✔️ The issue has been solved labels Feb 28, 2020
@alvaaz
Copy link
Author

alvaaz commented Feb 28, 2020

Thanks @MichalLytek. If someone is here because error then typegoose update.

The problem is that with the new typegoose, you need to add at least one query.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Community 👨‍👧 Something initiated by a community Documentation 📖 Issues about docs Solved ✔️ The issue has been solved
Projects
None yet
Development

No branches or pull requests

2 participants