GraphQL查询在客户端使用不同的服务器

时间:2017-04-03 22:20:33

标签: reactjs express graphql create-react-app react-apollo

我有一个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发出嵌套子组件的请求?

1 个答案:

答案 0 :(得分:0)

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

const client = new ApolloClient({
  networkInterface: createNetworkInterface({
    uri: "/graphql", // you might have missed the `/` at the beginning
  })
});