Type-graphql: Middleware broken?

Created on 9 Apr 2019  Â·  6Comments  Â·  Source: MichalLytek/type-graphql

Describe the bug
Simple middlewares that were copied and pasted from the docs are broken.

To Reproduce
I have created a minimal reproduction. See this repo and the README for instructions: https://github.com/elie222/type-graphql-middleware-bug

Expected behavior
I expect the middlewares not to throw errors.

Logs
LogAccess and ResolveTime are both in the src/index.ts file in the repo.

LogAccess middleware error:

{ [GraphQLError: next is not a function]
  message: 'next is not a function',
  locations: [ { line: 2, column: 3 } ],
  path: [ 'segments' ],
  extensions: 
   { code: 'INTERNAL_SERVER_ERROR',
     exception: { stacktrace: [Array] } } }

ResolveTime middleware error:

{ [GraphQLError: Cannot read property 'bind' of undefined]
  message: 'Cannot read property \'bind\' of undefined',
  locations: [ { line: 2, column: 3 } ],
  path: [ 'segments' ],
  extensions: 
   { code: 'INTERNAL_SERVER_ERROR',
     exception: { stacktrace: [Array] } } }
(node:12526) UnhandledPromiseRejectionWarning: TypeError: next is not a function
    at Object.<anonymous> (.../type-graphql-bug-reproduction/server/src/index.ts:78:42)

Enviorment (please complete the following information):

  • OS: Mac
  • Node v10.1.0
  • Package version 0.17.1
  • TypeScript version 3.3.4000

Additional context
-

Community Question Solved

Most helpful comment

You have wrong Typescript config - please change it to the supported one according to docs:

  "lib": ["esnext.asynciterable", "es2016"],
  "target": "es2016",

https://typegraphql.ml/docs/installation.html#typescript-configuration

After that it works in your repo.

All 6 comments

I have created a minimal reproduction.

It's not a minimal reproduction, it's probably a half of your project.
I cannot easily run in (database connection), debug it and it's hard to dig in the code related to db, mongo, etc.

Please try to reproduce it from scratch, maybe mergeSchemas or makeExecutableSchema is broking something, hard to say from your big project dump.

Here is an example of a minimal reproduction:
https://github.com/19majkel94/type-graphql/issues/305

I removed most of the project. I did leave the Apollo and Accounts stuff in
intentionally but can remove all those too.

On Tue, 9 Apr 2019 at 16:23 Michał Lytek notifications@github.com wrote:

I have created a minimal reproduction.

It's not a minimal reproduction, it's probably a half of your project.
I cannot easily run in (database connection), debug it and it's hard to
dig in the code related to db, mongo, etc.

Please try to reproduce it from scratch, maybe mergeSchemas or
makeExecutableSchema is broking something, hard to say from your big
project dump.

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/19majkel94/type-graphql/issues/306#issuecomment-481249334,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AC8oX3eAxQBCuO2jNAZeRkvuxwzpUBlzks5vfJQ-gaJpZM4ckOxi
.

I updated the repo. Around 100 LOC now.

To run:

yarn
yarn watch

And then http://localhost:4000 and run:

query {
  segments {
    name
  }
}

You have wrong Typescript config - please change it to the supported one according to docs:

  "lib": ["esnext.asynciterable", "es2016"],
  "target": "es2016",

https://typegraphql.ml/docs/installation.html#typescript-configuration

After that it works in your repo.

Thanks. This is a separate question, but any idea why this now breaks when making the above suggested change:

  @Field(type => PolicyVersionTree)
  @Column(type => PolicyVersionTree)
  tree: PolicyVersionTree
}

@ObjectType()
export class PolicyVersionTree {
  @Field(type => [Channel])
  channels: Channel[]
}

Error:

  tree: PolicyVersionTree
        ^
ReferenceError: PolicyVersionTree is not defined

You should keep one class in one file to prevent all of the cirular deps problem and ReferenceError.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Tybot204 picture Tybot204  Â·  3Comments

MichalLytek picture MichalLytek  Â·  3Comments

laukaichung picture laukaichung  Â·  3Comments

laukaichung picture laukaichung  Â·  3Comments

MichalLytek picture MichalLytek  Â·  4Comments