如何在Apollo客户端中一起使用这4个部分:Apollo刷新令牌

huangapple go评论71阅读模式
英文:

How to use these 4 all together in apollo client in Apollo refresh token

问题

const client = new ApolloClient({
cache: new InMemoryCache({ possibleTypes }),
link: from([authLink, refreshTokenLink, httpLink, errorLink]),
});

这是我的Apollo代码,在这些链接中,link: from([authLink, refreshTokenLink, httpLink]) 正常工作,但在添加 errorLink 后没有调用。还尝试了使用 concat 并更改数组值,但也不起作用。如果有任何可用的示例,请告诉我。

英文:
const client = new ApolloClient({
cache: new InMemoryCache({ possibleTypes }),
link: from([authLink,refreshTokenLink,httpLink, errorLink]),
});

This is my apollo code and on these these
link: from([authLink,refreshTokenLink,httpLink]) are working fine on adding errorLink that is not calling. Also tried with concat and change the array values but it's not working also let me know if there is any working example.

答案1

得分: 1

httpLink 是一个 "终端链接" - 它不会调用它后面的任何链接。所以这里的顺序很重要!

将你的 errorLink 放在 httpLink 前面 - 一般来说,一个链接只能看到它后面的内容的结果,所以它放在最后是没有用的。

在你当前的顺序中,它是这样的:

  • authLink 调用 refreshTokenLink(可以将内容传递给 refreshTokenLinkhttpLink 并查看它们返回什么)
  • refreshTokenLink 调用 httpLink(可以将内容传递给 httpLink 并查看它返回什么)
  • httpLink 发出请求并返回结果。

你需要这样做:

from([authLink, refreshTokenLink, errorLink, httpLink]) 

因为要让 errorLink 有用,它需要看到从 httpLink 返回的错误。

英文:

httpLink is a "terminal link" - it won't call any link behind it. So ordering is important here!

Move your errorLink before the httpLink - generally, a link can only see the results of what comes behind it, so it wouldn't be useful at the end.

With your current odering, it goes

  • authLink calls refreshTokenLink (can pass things into refreshTokenLink and httpLink and see what they return)
  • refreshTokenLink calls httpLink (can pass things into httpLink and see what it returns)
  • httpLink makes a request and returns the result.

You need to go

from([authLink,refreshTokenLink,errorLink,httpLink]) 

because for the errorLink to be any useful, it needs to see the errors returned from the httpLink.

huangapple
  • 本文由 发表于 2023年7月20日 20:41:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/76730005.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定