elysia icon indicating copy to clipboard operation
elysia copied to clipboard

Subscriptions work but the type annotations are wrong

Open mrctrifork opened this issue 2 years ago • 1 comments

What version of Elysia.JS is running?

0.8.17

What platform is your computer?

Darwin 23.3.0 arm64 arm

What steps can reproduce the bug?

  1. Setup the most basic server using Elysia and the official plugin graphql-yoga
  2. Head over to graphql yoga subscriptions and assemble their countdown example.

If you follow the pattern:

const types = /* GraphQL */` ...the types ` as const

const resolvers = {...} satisfies Resolver<CreateMobius<typeof types, AppScalars>, AppContext>

You'll see the following error message:

Object literal may only specify known properties, and 'subscribe' does not exist in type '(parent: unknown, args: { from: number; }, context: { request: Request; headers: Map<string, string>; user: undefined; }, info: unknown) => MaybePromise<number>'.ts(2353)
index.d.ts(177, 15): The expected type comes from property 'countdown' which is declared here on type '{ countdown: (parent: unknown, args: { from: number; }, context: { request: Request; headers: Map<string, string>; user: undefined; }, info: unknown) => MaybePromise<number>; }'
(property) subscribe: (_: any, { from }: {
    from: any;
}) => AsyncGenerator<{
    countdown: any;
}, void, unknown>

If we ignore the error it works fine. It's just the compiler

What is the expected behavior?

TypeScript shouldn't raise an error.

What do you see instead?

TypeScript error

Additional information

I believe the underlying problem has to be solved by patching mobius

mrctrifork avatar Feb 23 '24 18:02 mrctrifork

any idea how enable subscription (graphql-ws) using yoga ?

kamalkech avatar Jun 29 '24 19:06 kamalkech