Apollo HttpLink异步

问题描述 投票:1回答:1

对于以下代码:

const apolloClient = new ApolloClient({
  cache: new InMemoryCache(),
  link: new HttpLink({
    uri: endpoint,
    headers: {
      'Content-Type': 'application/json',
      Authorization: `Bearer ${token}`
    }
  })
});

我需要异步获取endpointtoken。我该怎么办?

谢谢

asynchronous apollo react-apollo apollo-client
1个回答
0
投票

我认为您可以动态设置它by making the uri a function。我不确定它是否每次发出请求时都会重新读取链接。看起来像这样(用TypeScript编写,但仍应可被JS解析)

© www.soinside.com 2019 - 2024. All rights reserved.