微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Apollo UseSubscription Hook 抛出“页面加载时连接中断”在控制台中

如何解决Apollo UseSubscription Hook 抛出“页面加载时连接中断”在控制台中

我的 Apollo 版本是

"@apollo/client": "^3.3.11",

我正在使用

"apollo-link-ws": "^1.0.20","apollo-utilities": "^1.3.4",

根据请求的类型连接到不同的端点,如下所示。

  const httpLink = new HttpLink({
    uri: process.env.REACT_APP_GQL_ROOT,// Server URL (must be absolute)
    credentials: 'same-origin',// Additional fetch() options like `credentials` or `headers`
    headers: {
      authorization: token ? `Bearer ${token}` : '',},})

  // create a link for websocktes that directly contacts hasura hasura
  const createWsLink = new WebSocketLink({
    uri: process.env.REACT_APP_SUBSCRIPTION_ROOT,options: {
      reconnect: true,lazy: true,connectionParams: {
        authorization: token ? `Bearer ${token}` : '',})

  // create a link for websockets for nest graphql subscriptions
  const createnestWsLink = new WebSocketLink({
    uri: process.env.REACT_APP_nesT_SUB_ROOT,})

  // join the split links for a unified apollo client
  const link = split(
    // split based on operation type
    ({ query }) => {
      const { kind,operation } = getMainDeFinition(query)
      return kind === 'OperationDeFinition' && operation === 'subscription'
    },// split websocket links based on operation name
    split(({ operationName }) => operationName.startsWith('nesT_'),createnestWsLink,createWsLink),httpLink,)

  const client = new ApolloClient({
    uri: process.env.REACT_APP_GQL_ROOT,link,cache: new InMemoryCache(),})

但是我总是在控制台中收到错误消息 “加载时与“url”的连接中断”。 无论如何我都可以弄清楚为什么连接总是被中断。 如果没有,我有什么办法可以抑制这些错误

image of connection was interrupted errors

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。