Skip to content

The recipe for graphql-ws client with apollo is not working with Vanilla JS #300

Answered by enisdenjo
NicoSan20 asked this question in Q&A
Discussion options

You must be logged in to vote

A simple Google search with "typescript to javascript" gives you the tools. TS Playground from the results would give you a JavaScript only version like this:

// for Apollo Client v3:
import { ApolloLink, Observable, } from '@apollo/client/core';
// or for Apollo Client v2:
// import { ApolloLink, Operation, FetchResult, Observable } from 'apollo-link'; // yarn add apollo-link
import { print } from 'graphql';
import { createClient } from 'graphql-ws';
class WebSocketLink extends ApolloLink {
    constructor(options) {
        super();
        this.client = createClient(options);
    }
    request(operation) {
        return new Observable((sink) => {
            return this.client.subscribe(

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@NicoSan20
Comment options

Answer selected by NicoSan20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #299 on January 24, 2022 16:02.