【问题标题】:GraphQL Queries using different server on client side在客户端使用不同服务器的 GraphQL 查询
【发布时间】:2017-08-28 22:45:51
【问题描述】:

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

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

"localhost:3000/topic/:id"

因为找不到“http://localhost:3000/topic/graphql”而返回 404

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

【问题讨论】:

  • 你能贴出设置路由的代码,以及发出请求的位置吗?

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


【解决方案1】:

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

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

【讨论】:

  • 非常感谢!是的,我在graphql前面设置了没有/的networkInterface。谢谢!
猜你喜欢
  • 2016-08-31
  • 2020-03-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-02-18
  • 2015-02-28
  • 1970-01-01
相关资源
最近更新 更多