英文:
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(可以将内容传递给refreshTokenLink和httpLink并查看它们返回什么)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
authLinkcallsrefreshTokenLink(can pass things intorefreshTokenLinkandhttpLinkand see what they return)refreshTokenLinkcallshttpLink(can pass things intohttpLinkand see what it returns)httpLinkmakes 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论