Skip to content

Graphql-ws with apollo client v2 #269

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

You must be logged in to vote

v3 is not much different from v2. Here's a quick and untested integration of graphql-ws with Apollo Client v2:

import { print } from 'graphql';
import { createClient, ClientOptions, Client } from 'graphql-ws';
import { ApolloLink, Operation, FetchResult, Observable } from 'apollo-link'; // yarn add apollo-link

// **literally** copied over from the "Client usage with Apollo" recipe
class WebSocketLink extends ApolloLink {
  private client: Client;

  constructor(options: ClientOptions) {
    super();
    this.client = createClient(options);
  }

  public request(operation: Operation): Observable<FetchResult> {
    return new Observable((sink) => {
      return this.client.subscribe<FetchR…

Replies: 1 comment 10 replies

Comment options

You must be logged in to vote
10 replies
@enisdenjo
Comment options

@alexsserban
Comment options

@enisdenjo
Comment options

@enisdenjo
Comment options

@alexsserban
Comment options

Answer selected by alexsserban
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