0

我有一个 Create-React-App 服务器,它将所有 API 请求代理到我的后端 Express-GraphQL 服务器,位于 localhost:3001

每当我在主页组件'/'上发出请求时,它都会将请求发送到“localhost:3000/graphql”,它工作得很好。但是如果我在嵌套子组件上发出请求,它将请求发送到类似的东西

"localhost:3000/topic/:id"

它发回 404,因为它找不到“ http://localhost:3000/topic/graphql

所以我的问题是,我如何告诉 React 仍然向 localhost:3000/graphql 发出嵌套子组件的请求?

4

1 回答 1

0

对于 react-apollo,当你创建一个新的 ApolloClient 时,将 uri 设置为/graphql

const client = new ApolloClient({
  networkInterface: createNetworkInterface({
    uri: "/graphql", // you might have missed the `/` at the beginning
  })
});
于 2017-04-03T23:25:39.430 回答