SubscriptionForwarder Typescript issue with graphql-ws
JarvisH opened this issue · comments
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.
That makes sense. Even if someone are using some other implementation they could just provide a no op
functions.