Apollo 客户端/使用本地主机响应本机错误 Apollo 客户端配置

问题描述

我有一个可与 Apollo 客户端 (grapqhl) 配合使用的 React Native 应用程序,问题是我有一个生产 API,Apollo 客户端可以正常工作,但是如果我将 apollo 配置中的 uri 更改为 {{ 1}},我的 IDE 控制台抛出以下错误

localhost:8000/graphql

我已经能够针对类似问题查看一些 questions,但我发现了两件事:

  1. 类似问题的问题真的很老了,有些东西已经改变了,随着阿波罗 3 的发布更多
  2. 他们建议的解决方案没有奏效,例如将本地主机更改为我机器的 IP。
  3. 我正在使用 expo 运行 react native,我尝试在 expo go 和 android studio 中运行该应用程序,但没有任何好的结果。

Apollo 客户端配置

[Unhandled promise rejection: Error: Network request Failed]
at http://192.166.0.14:19000/node_modules%5Cexpo%5CAppEntry.bundle
?platform=android&dev=true&hot=false&minify=false:358011:25 in new
 ApolloError
at node_modules\@apollo\client\core\core.cjs.js:1081:45 in self.ge
tObservableFromLink.subscribe$argument_0.error
at node_modules\zen-observable\lib\Observable.js:139:8 in notifySu
bscription
at http://192.168.0.14:19000/node_modules%5Cexpo%5CAppEntry.bundle
?platform=android&dev=true&hot=false&minify=false:356825:4 in onNo
tify
at node_modules\zen-observable\lib\Observable.js:239:4 in <anonymo
us>
at node_modules\@apollo\client\utilities\utilities.cjs.js:946:24 i
n iterateObserveRSSafely
at <anonymous>:null in Array.forEach
at node_modules\@apollo\client\utilities\utilities.cjs.js:945:4 in
 iterateObserveRSSafely
at http://192.168.0.14:19000/node_modules%5Cexpo%5CAppEntry.bundle
?platform=android&dev=true&hot=false&minify=false:339027:12 in Obj
ect.error
at node_modules\zen-observable\lib\Observable.js:139:8 in notifySu
bscription

环境信息

import { ApolloClient,InMemoryCache } from '@apollo/client';

const client = new ApolloClient({
  uri: 'http://localhost:8000/graphql/',cache: new InMemoryCache()
});

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)