首页 > 解决方案 > 向我的 graphql API 发起查询时出现网络错误

问题描述

这是我在进行查询时收到的错误消息:

[Network error]: ServerParseError: JSON.parse: unexpected character at line 1 column 1 of the JSON data

当将我的 ApolloClient 的 uri 设置为http://localhost:4000/graphql并在本地运行服务器时,查询在本地运行良好。

但是,如果我将服务器部署到 heroku,然后将客户端的 uri 设置为https://my-app.herokuapp.com/它不起作用,我会收到上面的错误消息。网络选项卡向我的 heroku 应用程序的 POST 请求显示 404,“无法 POST”

heroku 日志在推送时没有显示错误。

知道我在这里缺少什么吗?我检查了所有我能找到的教程,我没有发现任何明显的缺失。

这是我的客户要求:

const client = new ApolloClient({ uri: 'https://my-app.herokuapp.com/', headers: { authorization: "Bearer API_KEY", 'content-type': 'application/json' } });

标签: herokugraphqlapolloapollo-boost

解决方案


URI不应该是uri: https://my-app.herokuapp.com/graphql吗?由于您的 localhost 端点是/graphql.

希望能帮助到你 :)


推荐阅读