Rob*_*nia 8 graphql react-native apollo-client
我想通过 Apollo 向此服务器发送请求并获取查询:
const client = new ApolloClient({
link: new HttpLink({
uri:' http://mfapat.com/graphql/mfaapp/ '}),
cache: new InMemoryCache()
})
const FeedQuery = gql
query{
allFmr{
fmrId,
name,
studio,
bedRm1,
bedRm2,
bedRm3,
bedRm4
}
}
` 但我正面临此错误消息:
未处理(在 react-apollo:Apollo(FMRScreen) 中)错误:网络错误:意外令牌 < JSON 中的位置 1
at new ApolloError (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:109336:32)
at ObservableQuery.currentResult (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:109447:28)
at GraphQL.dataForChild (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:103192:66)
at GraphQL.render (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:103243:37)
Run Code Online (Sandbox Code Playgroud)
....
但是我可以轻松地在浏览器中打开“ http://mfapat.com/graphql/mfaapp/ ”并进行查询。有谁知道问题出在哪里?
目前,Apollo 将从服务器发送的所有内容都视为 JSON。但是,如果出现错误,您的服务器可能会发送 HTML 来显示基本错误页面。
要查看错误,请打开开发工具,然后查看网络选项卡。这显示了 401 错误示例:
正如您所看到的,如果您将其解析为 JSON,您会偶然发现第一个字符:<这就是我们的错误消息的来源。
阅读发送的特定错误使您能够修复错误。
要修复一般错误,请将服务器配置为在 HTTP 错误上发送 JSON,而不是 HTML 代码。这应该允许 Apollo 解析它并显示一个合理的错误页面。
编辑:另请参阅此讨论- 希望他们会更改默认的 Apollo 行为,或者至少提供有用的讨论。
| 归档时间: |
|
| 查看次数: |
7470 次 |
| 最近记录: |