【发布时间】:2019-12-05 08:05:44
【问题描述】:
我使用 apollo-link-error 来处理 graphql 错误。我需要知道onError回调中当前链接的uri。但是,回调的签名如下:
函数({操作、响应、graphQLErrors、networkError、forward})
似乎无法从这些参数中获取 uri。所以我错过了什么吗?还是我需要使用其他工具来达到这个目的? 事实上,我需要知道 uri 用于重试目的(重试请求另一台服务器)。
我如下配置客户端,
var uriList = [uri1, uri2]
const customFetch = (uri, options) => {
const dynamicURI = getOneURIFromURIList()
return fetch(dynamicURI, options);
}
const errorLink = onError(({ networkError, operation, forward }) => {
if (needRetry(networkError)) {
// Here, if I know the URI of the terminating link, I can removed it
// from the uriList, and customFetch will not choose it again.
return forward(operation)
}
})
const link = errorLink.concat(createHttpLink({ fetch: customFetch }))
【问题讨论】:
-
分享您的客户端配置,包括链接,将有助于为您的问题提供更具体的答案。没有任何示例代码,很难提供一个笼统的答案。
-
@DanielRearden 感谢您的热情回复。我重新编辑了这个问题。在重新编辑的过程中,我发现customFetch的
uri参数可能是我想要的。当重试发生时,它是上一次调用getOneURIFromURIList的URI吗?我还没试过。 -
很遗憾,经过测试,发现customFetch的
uri参数没有变化,默认是/graphql。 -
使用未经测试但可行的解决方法来编辑我的答案,以解决您正在尝试做的事情。
标签: graphql graphql-js