Apollo-module: Can an example be made for Nuxt with subscriptions?

Created on 14 Nov 2017  路  9Comments  路  Source: nuxt-community/apollo-module

Can someone please make an official example using subscriptions with the new v3 :)

Can't seem to get it working with v2.1.1 :( Thank you

This question is available on Nuxt.js community (#c31)
question

Most helpful comment

This is my clientDefault config file:

import { HttpLink } from 'apollo-link-http'
import { InMemoryCache } from 'apollo-cache-inmemory'
import { WebSocketLink } from 'apollo-link-ws'
import { SubscriptionClient } from 'subscriptions-transport-ws'

export default (ctx) => {
  let link = null

  if (ctx.isServer) {
    link = new HttpLink({ uri: 'http://localhost:3000/graphql' })
  } else {
    const client = new SubscriptionClient('ws://localhost:3001/graphql', {
      reconnect: true
    })

    link = new WebSocketLink(client)
  }

  const cache = new InMemoryCache()

  return {
    link,
    cache
  }
}

Server side uses HTTP Link, Client uses Websocket link.

All 9 comments

@lolcoolkat your question should be better posted in https://github.com/Akryum/vue-apollo, this package is just the wrapper for vue-apollo code

Personally I don't use subscriptions but happy if someone would provide some code to extend the README

Yes this only has the httpLink. How would it look like with a subscription ws link?

https://www.apollographql.com/docs/link/links/ws.html

This is my clientDefault config file:

import { HttpLink } from 'apollo-link-http'
import { InMemoryCache } from 'apollo-cache-inmemory'
import { WebSocketLink } from 'apollo-link-ws'
import { SubscriptionClient } from 'subscriptions-transport-ws'

export default (ctx) => {
  let link = null

  if (ctx.isServer) {
    link = new HttpLink({ uri: 'http://localhost:3000/graphql' })
  } else {
    const client = new SubscriptionClient('ws://localhost:3001/graphql', {
      reconnect: true
    })

    link = new WebSocketLink(client)
  }

  const cache = new InMemoryCache()

  return {
    link,
    cache
  }
}

Server side uses HTTP Link, Client uses Websocket link.

@rnenjoy does your code work in your application?

Yes dude. Works great! Fixed it last night. Need more help?

@rnenjoy nope just asking I might extend our README with your ws example so great that you make it work

By the way, here a current example for Angular 2 just in case someone wants to adopt some code: https://alligator.io/angular/graphql-subscriptions/

Example is updated in the README

Was this page helpful?
0 / 5 - 0 ratings