elysiajs / elysia

Ergonomic Framework for Humans
https://elysiajs.com
MIT License
10.44k stars 223 forks source link

Subscriptions work but the type annotations are wrong #499

Open mrctrifork opened 8 months ago

mrctrifork commented 8 months ago

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

kamalkech commented 4 months ago

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