Meteor + Apollo订阅:Websocket连接关闭

时间:2018-05-17 06:21:35

标签: meteor apollo apollo-client apollo-server

我正在使用meteor并试图让Apollo Subscriptions工作,但我正在

WebSocket connection to 'ws://127.0.0.1:3000/sockjs/401/m892wugm/websocket' failed: Connection closed before receiving a handshake response在客户端。

我关注Server ConfigurationClient Configuration的apollographql.com指南,但我不太确定如何将客户端连接到服务器。

在客户端,我使用 ApolloClient ApolloLink Meteor auth 传递给GraphQL。

以下是代码:

客户端

import { ApolloClient } from 'apollo-client'
import { createHttpLink } from 'apollo-link-http'
import { InMemoryCache } from   'apollo-cache-inmemory'
import { ApolloLink } from 'apollo-link'

const httpLink = new createHttpLink()
const authLink = new ApolloLink((operation, forward) => {
  operation.setContext(() => ({
    headers: { 'meteor-login-token': Accounts._storedLoginToken() },
  }))
  return forward(operation)
})

export default ApolloClient = new ApolloClient({
  link: authLink.concat(httpLink),
  cache: new InMemoryCache(),
})

服务器

createApolloServer({
  schema,
  tracing: true,
  cacheControl: true,
})

new SubscriptionServer({
  schema,
  execute,
  subscribe,
}, {
  server: WebApp.httpServer,
  path: '/subscriptions',
})

Package.json(当然不是所有内容)

Meteor 1.6.1.1
...
"apollo-client": "^2.2.5",
"apollo-link": "^1.2.1",
"apollo-link-context": "^1.0.7",
"apollo-link-http": "^1.5.3",
"apollo-link-ws": "^1.0.8",
"subscriptions-transport-ws": "^0.9.9",
...

我在某处读到了将 noServer :true传递给SubscriptionServer()以解决冲突。错误确实消失了,但订阅似乎也无效。

是的,我已经关注了apollographql的Meteor Integration指南,但是那里的信息已经过时且不起作用。

0 个答案:

没有答案