kpfromer / nestjs-typegoose

Typegoose with NestJS
https://kpfromer.github.io/nestjs-typegoose/
MIT License
291 stars 73 forks source link

Basic NestJS typegoose/typegraphql example not working #60

Open elie222 opened 4 years ago

elie222 commented 4 years ago

I put up a basic project using NestJS, Typegoose and TypeGraphQL but the mongo query never returns: https://github.com/elie222/nestjs-typegraphql-typegoose-example

Specifically in this file:

https://github.com/elie222/nestjs-typegraphql-typegoose-example/blob/master/src/cats/cats.resolver.ts

  @Query(() => [Cat])
  async cats(): Promise<Cat[]> {
    console.log("gets here");

    const cats = await this.catsService.listCats();

    console.log("never gets here", cats);

    return cats;
  }

Not sure if this is an issue with this package or Typegoose, or likely I'm just not setting things up as expected. Would be nice to get some sort of feedback but the promise just never returns.

hasezoey commented 4 years ago

to get the right return types you would need to use https://typegoose.github.io/typegoose/docs/types/documentType/

maybe try @types/mongoose 5.6.x (5.7 is not yet tested with typegoose)

otherwise i dont see a problem

elie222 commented 4 years ago

There’s no problem with types. Running the app prints the first log but doesn’t print the second. It just never returns

Best, Eliezer

On Wed, Jan 29 2020 at 2:56 PM, hasezoey < notifications@github.com > wrote:

to get the right return types you would need to use https://typegoose.github.io/typegoose/docs/types/documentType/

maybe try @types/mongoose 5.6.x (5.7 is not yet tested with typegoose)

otherwise i dont see a problem

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub ( https://github.com/kpfromer/nestjs-typegoose/issues/60?email_source=notifications&email_token=AAXSQX7NMWGU4NTMIH6YQNDRAF4GXA5CNFSM4KNDSC32YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEKHC4II#issuecomment-579743265 ) , or unsubscribe ( https://github.com/notifications/unsubscribe-auth/AAXSQX2ROM3PGOIARGLFCUDRAF4GXANCNFSM4KNDSC3Q ).

hasezoey commented 4 years ago

@elie222 how to run your example repo? (i never used nest/graphql) i only got as far as to starting the server and locating localhost:3000/graphql (and /cats dosnt exists, where i would expect it)

elie222 commented 4 years ago

I decided to go with TypeORM instead in the end. Should be under cats { name } in Playground.

Best, Eliezer

On Wed, Jan 29, 2020 at 10:26 PM, hasezoey < notifications@github.com > wrote:

@ elie222 ( https://github.com/elie222 ) how to run your example repo? (i never used nest/graphql) i only got as far as to starting the server and locating localhost:3000/graphql (and /cats dosnt exists, where i would expect it)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub ( https://github.com/kpfromer/nestjs-typegoose/issues/60?email_source=notifications&email_token=AAXSQX2EN5VQOZBDXIJELT3RAHQ7ZA5CNFSM4KNDSC32YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEKITZ7Y#issuecomment-579943679 ) , or unsubscribe ( https://github.com/notifications/unsubscribe-auth/AAXSQX4MVABHUQMRVSNORALRAHQ7ZANCNFSM4KNDSC3Q ).

hasezoey commented 4 years ago

@elie222 i just tested it, and here is what i found: a simple log of mongoose.connection.readyState reveals that the default connection is not connect to the database, and so the query stalls and waits for the connection to be connected and from what i have seen, the model you use, Cat is associated with the default connection, but there is an non-default connection that is connected

@kpfromer could you help here? because the example in your repo seems to be almost the same as the one provided here

hasezoey commented 4 years ago

and when trying to use connectionName, it will result in #57

oliviermattei commented 4 years ago

I have a similar problem. https://github.com/oliviermattei/nestjs-graphql-typegoose-example

In my case, User module works perfectly but demand module is stuck when I use it. I have "error": "Failed to fetch. Please check your connection"

In fact the demand way should be better because of the fusion of model and type

Have you an Idea ?