graphql - graphql - 使用 apollo 客户端挂钩停止挂起的请求
问题描述
我正在尝试取消待处理的请求。
我正在关注我在其他问题上阅读过的本教程,但我无法取消任何请求。
我已经按照教程中的说明配置了 apollo 客户端。
阿波罗客户端代码:
const authMiddleware = new ApolloLink((operation, forward) => {
const locale: LocaleString = getLocale();
operation.setContext({
headers: {
"Accept-Language": locale,
authorization: `Bearer ${localStorage.getItem("token")}` || null,
"Content-Type": "application/json",
},
});
return forward(operation);
});
const restAPILink: any = new RestLink({
uri: `${getEnvVariable(REACT_APP_HIERARCHY_API)}/${apiVersion}/`,
endpoints: { ... }
});
const httpLink = new HttpLink({
uri: `${getEnvVariable(REACT_APP_GRAPHQL_API)}`,
});
const composedLink: any = ApolloLinkFrom([
cancelRequestLink,
restAPILink,
httpLink,
]);
const apolloClient = new ApolloClient({
cache: new InMemoryCache(),
link: concat(authMiddleware, composedLink),
connectToDevTools: true,
queryDeduplication: false,
});
阿波罗请求:
const getSupplyPoints = async () => {
setLoading(true);
setError(false);
const response = await client.mutate({
mutation: CONNECTIONS_DATA,
variables: {...},
context: {
requestTrackerId: uuidNameSpace(
"CONNECTIONS_DATA",
RequestNameSpace
),
},
});
setLoading(false);
setError(response?.errors ? true : false);
setData(response?.data);
};
阿波罗取消请求:
该文件与tutorial相同,如果在其中中止的地方,我添加了一个日志以显示它显示我的日志。
在控制台中显示请求已中止,但在网络选项卡上未显示取消先前的挂起请求。
我做错了什么??
解决方案
推荐阅读
- node.js - 如何使用单个读取流,进行多次转换并使用 Sharp 分别写入一个单独的流?
- flutter - comare 2 数组并获得 id 颤动
- c# - 为什么从 C# 代码运行此 CosmosDB SQL 查询会失败?
- r - 使用混合()运行 glmer 后 afex::all_fit() 出错
- c# - 如何以异步方法读取 URL
- javascript - 向对象添加新值
- python - 在浏览器中查看 Dash App 时 Heroku 应用程序部署错误
- sql - PolyBase创建外部表查询Hadoop,列数不匹配
- c++ - 调整大小时没有重载函数的实例
- r - 多元多元回归的 VIF 检验