Skip to content
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

type-graphql 0.18 #16

Open
birkir opened this issue Oct 30, 2019 · 13 comments
Open

type-graphql 0.18 #16

birkir opened this issue Oct 30, 2019 · 13 comments
Labels
bug Something isn't working
Milestone

Comments

@birkir
Copy link

birkir commented Oct 30, 2019

Hey, great work!!

I am trying to use it with a project where I need to use type-graphql 0.18.0-beta because of a bug in previous versions not allowing multiple buildSchema to work in a single nodejs instance.

However it may seem like that update broke this library, I don't get any errors or anything, but my @RelayedQuery decorated function don't show up.

MichalLytek/type-graphql#415

@Superd22
Copy link
Member

It shouldn't have any effect, but i'll check tomorrow, thanks for the issue ! :)

@Superd22 Superd22 added the bug Something isn't working label Nov 1, 2019
@Superd22
Copy link
Member

Superd22 commented Nov 1, 2019

Okay there's definitely a problem with 0.18.0 and the way we wait for types to become available before registering them in type-graphql's metadata.

@birkir for now a quick and dirty workaround that should work is to await one tick before building the schema.

// Just give auto-relay time to catch up
await Promise.resolve()
// And build the schema
const schema = await buildSchema({
  resolvers: [TestResolver],
});

I'll have to rewrite part of the lib to avoid that behavior, but in the meantime this should work. Lemme know

@Superd22 Superd22 added this to the 1.0 milestone Nov 1, 2019
@birkir
Copy link
Author

birkir commented Nov 1, 2019

Sounds good! Thanks for looking into this

@firmanjml
Copy link

Hi @Superd22, I'm currently using type-graphql 0.17.6 and having the same issue as described above.
Also tried await Promise.resolve() before buildSchema and got no luck.

await Promise.resolve()

const schema = await buildSchema({
    resolvers: [`${__dirname}/**/*.resolver.{ts,js}`],
    dateScalarMode: "timestamp"
});
@RelayedQuery(() => User)
    async users(
      @RelayLimitOffset() {limit, offset}: RelayLimitOffsetArgs
    ): Promise<[User[],number]> {
      return User.findAndCount({ 
        skip: offset,
        take: limit
      })
    }

package.json

{
   "name": "backend",
   "version": "0.0.1",
   "description": "",
   "devDependencies": {
      "@auto-relay/typeorm": "^0.12.5",
      "@types/express": "^4.17.2",
      "@types/node": "^8.0.29",
      "ts-node": "3.3.0",
      "ts-node-dev": "^1.0.0-pre.44",
      "typescript": "3.3.3333"
   },
   "dependencies": {
      "@types/graphql": "^14.5.0",
      "apollo-server-express": "^2.10.1",
      "auto-relay": "^0.12.5",
      "class-validator": "^0.11.0",
      "express": "^4.17.1",
      "graphql-relay": "^0.6.0",
      "pg": "^7.3.0",
      "reflect-metadata": "^0.1.10",
      "type-graphql": "^0.17.6",
      "typeorm": "0.2.22"
   },
   "scripts": {
      "start": "ts-node src/index.ts",
      "dev": "ts-node-dev src/index.ts"
   }
}

@idoshamun
Copy link

@Superd22 thanks for the hard work, I'm looking for a solution for 0.17.6 as well.

@Superd22
Copy link
Member

Superd22 commented Mar 6, 2020

Hey guys.

@idoshamun are you by any chance using a glob import aswell rather than direct imports ?
resolvers: ['${__dirname}/**/*.resolver.{ts,js}'] rather than resolvers: [MyEntityA, MyEntityB] ?

I have a suspicion that those are the culprit. There's definitively something iffy about the way AutoRelay hooks into TypeGraphql's lifecycle (hence the "wait one tick" workaround) and we'll have to rework that sooner rather than later anyway.

@idoshamun
Copy link

@Superd22 thanks for the quick response, this is exactly what I'm doing

@idoshamun
Copy link

Following your advice, it is now working! 🎉
One issue that I can see is that it generates undefinedPageInfo type. I believe the undefined part is a bug.

type undefinedPageInfo {
  hasNextPage: Boolean!
  hasPreviousPage: Boolean!
  startCursor: String
  endCursor: String
}

@Superd22
Copy link
Member

Superd22 commented Mar 6, 2020

Following your advice, it is now working!
One issue that I can see is that it generates undefinedPageInfo type. I believe the undefined part is a bug.

type undefinedPageInfo {
  hasNextPage: Boolean!
  hasPreviousPage: Boolean!
  startCursor: String
  endCursor: String
}

Hey, i've just pushed 0.12.6, this should fix that :)

@idoshamun
Copy link

You're the best! Checking now

@idoshamun
Copy link

Works perfectly

@glennreyes
Copy link

Hey guys.

@idoshamun are you by any chance using a glob import aswell rather than direct imports ?
resolvers: ['${__dirname}/**/*.resolver.{ts,js}'] rather than resolvers: [MyEntityA, MyEntityB] ?

I have a suspicion that those are the culprit. There's definitively something iffy about the way AutoRelay hooks into TypeGraphql's lifecycle (hence the "wait one tick" workaround) and we'll have to rework that sooner rather than later anyway.

@Superd22 I'm looking forward seeing this fixed soon! Maybe you could give any pointers to help fixing this problem?

Thanks for auto-relay!

@owenbendavies
Copy link

This also caused an issue for me. Commenting with my setup if it helps debug the issue, and can check any fixes.

Dependencies

"dependencies": {
    "@auto-relay/typeorm": "^0.13.1",
    "@middy/core": "2.5.3",
    "apollo-server-env": "^4.2.0",
    "apollo-server-errors": "^3.3.0",
    "apollo-server-lambda": "^3.5.0",
    "auto-relay": "^0.13.1",
    "axios": "^0.24.0",
    "class-validator": "^0.13.2",
    "faker": "^5.5.3",
    "graphql": "^15.7.2",
    "graphql-relay": "^0.9.0",
    "pg": "^8.7.1",
    "reflect-metadata": "^0.1.13",
    "source-map-support": "^0.5.21",
    "type-graphql": "^1.1.1",
    "type-graphql-dataloader": "^0.5.0",
    "typeorm": "^0.2.41",
    "typeorm-seeding": "^1.6.1"
  },

I'm importing resolvers via class rather than glob as needed for Typescript compilation / packaging

  const schema = await buildSchema({
    resolvers: [AccountResolver, etc],
  });

And adding

await Promise.resolve();

just before buildSchema did help for now.

Thank you for you brilliant work, much nicer than manually writing all the connection classes manually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants