【发布时间】:2021-02-05 22:15:47
【问题描述】:
"react-apollo": "3.1.5",
“react-native”:“https://github.com/expo/react-native/archive/sdk-38.0.2.tar.gz”
“世博”:“38.0.0”
我正在尝试从本地 asyncStorage 获取我的 url(主要是因为我的 url 在登录后从两个 url 中挑选并分配给 asyncStorage)。 这是我已经尝试过的,但我一直得到未定义的数据
const asyncHttpLink = setContext(async (_, {headers, ...context}) => {
const url = await getUrlFromAsyncStorage();
return createHttpLink({
uri: url ? url : '',
...context,
});
});
然后我将它分配到我的 Appolo 中
const client = new ApolloClient({
... other property as cache, type etc. ...
link: ApolloLink.from([
... other links ...
asyncHttpLink,
]),
});
响应时,我得到所有属性,除了始终未定义的数据
[
"variables",
"refetch",
... other 7 ...,
"error",
"called",
"data", <== always undefined
"client",
]
但是如果我使用标准的 createHttpLink,一切都可以正常工作
const httpLink = createHttpLink({
uri: desiredUrl,
});
有人追过同样的情况吗?
【问题讨论】:
标签: javascript react-native apollo react-apollo