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

SubscriptionForwarder Typescript issue with graphql-ws #186

Closed
JarvisH opened this issue Jan 19, 2023 · 1 comment
Closed

SubscriptionForwarder Typescript issue with graphql-ws #186

JarvisH opened this issue Jan 19, 2023 · 1 comment
Labels
🐛 bug Something isn't working 👕 TypeScript Typescript or typing issue

Comments

@JarvisH
Copy link

JarvisH commented Jan 19, 2023

When using graphql-ws like so:

import { createClient } from 'graphql-ws'
const wsClient = createClient(...)
...
use: [
      handleSubscriptions(operation => {
        return {
          subscribe: obs => {
            wsClient.subscribe(
              {
                query: ...,
                variables: ...
              },
              obs
            )
         

            return {
              unsubscribe: () => {}
            }
          }
        }
      }),

The following Typescript error occurs for the obs argument:

Argument of type 'ObserverLike<StandardOperationResult<any>>' 
is not assignable to parameter of type 'Sink<ExecutionResult<any, ObjMap<unknown>>>'

It essentially boils down to this Villus interface:

interface ObserverLike<T> {
    next?: (value: T) => void;
    error?: (err: any) => void;
    complete?: () => void;
}

vs. this grapqhl-ws interface:

interface Sink<T = unknown> {
    next(value: T): void;
    error(error: unknown): void;
    complete(): void;
}

I can understand the difficulty of ensuring compatibility with all sorts of external libraries, on the other hand, if the properties in interface ObserverLike do not have to be optional it would be an easy fix.

@logaretm
Copy link
Owner

logaretm commented Feb 8, 2023

That makes sense. Even if someone are using some other implementation they could just provide a no op functions.

@logaretm logaretm added 🐛 bug Something isn't working 👕 TypeScript Typescript or typing issue labels Feb 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working 👕 TypeScript Typescript or typing issue
Projects
None yet
Development

No branches or pull requests

2 participants