MichalLytek / type-graphql

Create GraphQL schema and resolvers with TypeScript, using classes and decorators!
https://typegraphql.com
MIT License
7.98k stars 674 forks source link

Types from 2.0.0-beta.6 have broken the alternative `subscribe` method signature. #1662

Closed robinelvin closed 2 months ago

robinelvin commented 3 months ago

Describe the Bug Types from 2.0.0-beta.6 have broken the alternative subscribe method signature.

To Reproduce

Use this method signature:

class SampleResolver {
  // ...
  @Subscription({
    subscribe: (root, args, context, info) => {
      return someIterator;
    },
  })
  newNotification(): Notification {
    // ...
  }
}

Typescript reports:

Type '(root: any, args: any, context: any, info: any) => AsyncIterator<unknown, any, undefined>' is not assignable to type 'SubscriptionSubscribeFunc'.
  Target signature provides too few arguments. Expected 4 or more, but got 1.ts(2322)
Subscription.d.ts(9, 5): The expected type comes from property 'subscribe' which is declared here on type 'SubscriptionOptions'

Expected Behavior The type check should pass.

Logs If applicable, add some console logs to help explain your problem. You can paste the errors with stack trace that were printed when the error occurred.

Environment (please complete the following information):

Additional Context This was previously working with the package declaration of "type-graphql": "next", To fix another unrelated problem I had to remove my yarn.lock file and re-create which I think must have upgraded type-graphql from whichever version I had previously.

MichalLytek commented 3 months ago

Please do not use "type-graphql": "next" but point to selected beta version in the package.json. Then when new beta is published, please read the release notes and update the package version.

someIterator

Please create a minimal, reproducible code example. Be aware that the typings have been fixed and graphql-subscription pub sub iterator has wrong typing.

robinelvin commented 3 months ago

I've tried the beta versions one by one and the latest working version for me is 2.0.0-beta.2

Sorry if I'm misunderstanding but I don't know why I am unable to use this subscribe method signature now if I am following the example from https://typegraphql.com/docs/subscriptions.html#creating-subscriptions which clearly shows it.

For clarification I am talking about the method parameters not the return type.

MichalLytek commented 3 months ago

Please create a minimal reproducible code example repository. I can't debug from your super small snippets.

MichalLytek commented 2 months ago

I have found what's wrong in your example. The docs were wrong or outdated. The proper signature of this function is subscribe: ({ root, args, context, info }) => { ... }.

I've updated the docs in 20271ba, so closing this issue🔒