问题描述
我正在尝试取消待处理的请求。
我正在关注这个tutorial,我已经阅读了其他问题,但我无法取消任何请求。
我已经按照教程的说明配置了 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 是一样的,在里面如果sould abort,我添加了一个日志来显示我的日志。
在控制台中显示请求已中止,但在网络选项卡上没有显示取消之前的待处理请求。
我做错了什么??
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)