【发布时间】:2020-11-05 04:34:24
【问题描述】:
我的脚本设置如下:
"start-dev": "npm-run-all -p client server db",
"client": "gatsby develop",
"server": "nodemon server.js",
"db": "json-server db.json"
所以对于开发,我有一个由 json-server 提供的模拟数据库和一个由 json-server 提供的端点。所以我按照docs 安装了插件。并将插件配置为:
{
resolve: `gatsby-source-graphql`,
options: {
typeName: `racing`,
fieldName: 'members',
url: 'http://localhost:3000/api/members',
},
},
{
resolve: `gatsby-source-graphql`,
options: {
typeName: `racing`,
fieldName: 'teams',
url: 'http://localhost:3000/api/teams',
},
},
当我运行yarn run start-dev 时出现错误:
"gatsby-source-graphql" threw an error while running the sourceNodes lifecycle:
Response not successful: Received status code 404
ServerError: Response not successful: Received status code 404
另外还有一些堆栈跟踪信息。最终我获得了前往 GraphQL 的常用链接(https:localhost:8000/__graphql),但我在此工具的可用查询中看不到 API 字段名。所以总体问题是我应该如何设置查询“第三方”API?具体来说,这是预期的错误吗?如何使用 GraphQL 工具查询 API?
谢谢。
【问题讨论】:
-
这个错误是你写错graphql查询时出现的,请问可以添加这些查询吗!
-
你可以配置
gatsby-source-graphql使用的fetch实现。您可以使用它来打印它发出的请求。由于它是 404,因此请求可能会发送到错误的地址。见github.com/gatsbyjs/gatsby/issues/24603#issuecomment-636000987 -
@BloodyLogic 错误来自配置。错误发生时启动时未尝试查询。
-
@ehrencrona 感谢您提供“获取”选项的提示。您是否介意将我指向有关此选项的文档,以便我知道它的作用并可能帮助我诊断问题?