node.js - 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(),
});
我正在尝试增加超时,但我无法做到。我也尝试了服务器端的连接超时(快速),但注意到有帮助。
解决方案
推荐阅读
- javascript - 在对象数组中搜索最新的匹配记录
- php - Laravel:{ } 运算符的含义和目的是什么?
- python - 如何打印集群和树状图?
- spring - PropertyReferenceException: 没有属性
- java - Java 字符串指数
- sql - 如何有效地从同一个表中的不同列和行返回数据?
- firebase - Flutter Firestore 和 StreamBuilder
- vba - 使用 VBA 将多个 Outlook 电子邮件保存到驱动器
- python-3.x - 密码学解密问题
- python - 在具有 DateTime 索引的 Pandas DataFrame 中查找每天第一次和最后一次出现的值的索引位置