Unable to get subscriptions working with Urql
See original GitHub issueHi I’m having an issue getting subscriptions to function with Urql, I am using a class created using examples in docs
class WebSocketLink {
private client: Client;
constructor(config: ClientOptions) {
this.client = createClient(config);
}
public request(op: SubscriptionOperation): Observable<ExecutionResult> {
return new Observable((sink) => {
return this.client.subscribe<ExecutionResult>(
{ query: op.query, variables: op.variables as Record<string, unknown> | null | undefined },
{
...sink,
error: (err) => {
console.log('Error: ', err);
if (err instanceof Error) {
sink.error(err);
} else if (err instanceof CloseEvent) {
sink.error(new Error(`Socket closed with even ${err.code}` + err.reason ? `: ${err.reason}` : ''));
} else {
sink.error(new Error(err.map(({ message }) => message).join(',')));
}
},
},
);
});
}
}
Below is what Urql passes to client.subscribe of which I extract query and variables and pass them on.
export interface SubscriptionOperation {
query: string;
variables?: object;
key: string;
context: OperationContext;
}
When calling a subscription via Urql I get an error with code: 1002 which appears to be a low level Websocket protocol violation from what I can find. Comparing what is sent to the server from subscriptions-transport-ws and graphql-transport-ws there doesn’t appear to be a difference. I am authenticating connections via connectionParams.
I use Express/Postgraphile on the server which uses subscriptions-transport-ws, I am aware you have a pull request to replace subscriptions-transport-ws with your implementation, so unsure if this is a compatibility issue, an error on my part or something else.
Many thanks.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)

Top Related StackOverflow Question
Thanks @enisdenjo! I had thought that may be the problem but wasn’t 100% sure, I will try the your fork and see how it goes.
@isuhendro because that branch has been merged to PostGraphile a while ago. It ships with
graphql-wsbuilt in since v4.11.0.