Issue with subscriptions in VueJS/Nuxt.JS


#1

Here is my following default.js file for the ApolloClient plugin …

import { ApolloLink, concat, split } from 'apollo-link’
import { HttpLink } from 'apollo-link-http’
import { InMemoryCache } from 'apollo-cache-inmemory’
import { WebSocketLink } from 'apollo-link-ws’
import { getMainDefinition } from ‘apollo-utilities’

export default (ctx) => {
const httpLink = new HttpLink({ uri: ‘http://localhost:60000/simple/v1/xxxxxxxxxxxxxxxxxxx’ })

// Create a WebSocket link:
let wsLink
if (ctx.isClient) {
wsLink = new WebSocketLink({
uri: ws://localhost:60000/subscriptions/v1/xxxxxxxxxxxxxxxxxxx,
options: {
reconnect: true
}
})
}

const authMiddleware = new ApolloLink((operation, forward) => {
// add the authorization to the headers
const token = ctx.store.state.user ? ctx.store.state.user.token : null
operation.setContext({
headers: {
authorization: Bearer ${token}
}
})
return forward(operation)
})

const link = split(
// split based on operation type
({ query }) => {
const { kind, operation } = getMainDefinition(query)
return kind === ‘OperationDefinition’ && operation === ‘subscription’
},
httpLink,
wsLink
)

return {
link: concat(authMiddleware, link),
cache: new InMemoryCache()
}
}

With Nuxt.JS the subscriptions are only run on the client.

I am getting the following error client side which leads me to believe something in my configuration is wrong.

The provided query doesn’t include any known model name. Please check for the latest subscriptions API.

And this is NOT an issue with any of my queries. I have tested them multiple times… so please don’t ask me to check anything about models etc… it has something to do with the configuration of my file!

If anyone has insight that would be great!


#2
  • Either, you are sending a subscription query which uses a model name that does not exist in your service
  • or, you added a new model or renamed an existing one, and the change has not been populated to the local subscription endpoint yet.

In the former case, double check your types.graphql and the subscription query.

In the latter case, graphcool local stop and graphcool local up should reload the subscription schema correctly. If you can reliably reproduce the error that the schema is not adjusted correctly after you deploy changes, please provide a reproduction here: https://github.com/graphcool/framework


#3

Figured this out, but thanks Nilan!


#4

I’m having a similar issue - could you tell me how you fixed yours?