首页 > 解决方案 > GraphQL apollo 客户端因套接字挂起而崩溃

问题描述

我有一个 Graphql apollo-client 和 Apollo server (Node.js) 都工作正常,但是当服务器需要超过 2 分钟来处理数据时,我的 apollo-client 崩溃了

“网络错误:对 http://localhost:8080/graphql 的请求失败,原因:套接字挂起”

这是我的阿波罗客户端配置

        const httpLink = () => (createHttpLink({
        uri: 'http://localhost:5000/graphql',
        fetch: fetch as any
      }));

      const errorLink = onError(({ graphQLErrors, networkError }) => {
        if (graphQLErrors) {
          graphQLErrors.map(({ message, locations, path }) =>
            console.log(`GraphQL Error: ${message}`),
          );
        }
        if (networkError) {
          console.log(`Network Error: ${networkError.message}`);
        }
      });

      const timeoutLink = new ApolloLinkTimeout(600000);
    const links = ApolloLink.from([
        errorLink,
        httpLink(),
        timeoutLink as any
      ]);
    this.client = new ApolloClientBase({
        link: links,
        cache: new InMemoryCache(),
    });

我正在尝试增加超时,但我无法做到。我也尝试了服务器端的连接超时(快速),但注意到有帮助。

标签: node.jsexpressgraphqlapollo-clientapollo-server

解决方案


推荐阅读