Apollo Server 没有套接字连接

Apollo Server has no socket connection

我有一个 GraphQL 服务器 运行 Type-GraphQL + Apollo,所以我想使用订阅。 对于前端,我使用的是 NextJS + Apollos 客户端,但出现以下错误: WebSocket connection to: 'ws://localhost:8080/graphql' failed: SubscriptionClient.connect @ client.js?2ed1:427 eval @ client.js?2ed1:396

我在前端客户端中的代码如下所示:

const wsLink = process.browser ? new WebSocketLink({ // if you instantiate in the server, the error will be thrown
    uri: `ws://localhost:8080/graphql`,
    options: {
      reconnect: true
    }
  }) : null;
  
  const httplink = new HttpLink({
      uri: 'http://localhost:8080/graphql',
      credentials: "include"
  });
  
  const link = process.browser ? split( //only create the split in the browser
    ({ query }) => {
        const definition = getMainDefinition(query);
        return definition.kind === 'OperationDefinition' && definition.operation === 'subscription';
      },
    wsLink,
    httplink,
  ) : httplink;

const client = new ApolloClient({
    link,
    fetch,
    credentials: "include",
    cache: new InMemoryCache(),
});

export default client;

我切换到 apollo-link-ws 修复了它