如何解决“gatsby-source-graphql”在运行 sourceNodes 生命周期时抛出错误:响应不成功:收到状态代码 400
我安装了最新版本的 gatsby-source-graphql 以连接我公司开发的第三方 GraphQL API,但在尝试使用 gatsby-source-graphql 连接时出现 400 错误。
实际上,我公司配置的标头不同,他们使用 X-AUTH-TOKEN 而不是 gatsby-source-graphql 插件提供的授权。
为了更清楚,这里是我在源代码中设置 gatsby-source-graphql 的方法。
{
resolve: "gatsby-source-graphql",options: {
typeName: "Kl",fieldName: "kl",// Create Apollo Link manually. Can return a Promise.
createLink: pluginOptions => {
return createHttpLink({
uri: `https://kaleidoscope-graph-ql.herokuapp.com/graphql`,headers: {
authorization: `Bearer ${process.env.KL_TOKEN}`,},fetch,})
},
我应该得到 200 OK 并且能够使用 GraphiQL 接口查询我公司 API 的数据。公司
我的问题是,如何自定义标题以使其接受 X-AUTH-TOKEN 而不是 gatsby-source-graphql 插件提供的授权。
"gatsby-source-graphql" threw an error while running the source nodes lifecycle:
Response not successful: Received status code 400
ServerError: Response not successful: Received status code 400
- index.ts:114 Object.exports.throwServerError
[raganortho]/[apollo-link-http-common]/src/index.ts:114:17
- index.ts:145
[raganortho]/[apollo-link-http-common]/src/index.ts:145:11
- task_queues.js:95 processTicksAndRejections
internal/process/task_queues.js:95:5
解决方法
您是否尝试过类似的操作:
{
resolve: "gatsby-source-graphql",options: {
typeName: "Kl",fieldName: "kl",url: "https://kaleidoscope-graph-ql.herokuapp.com/graphql",// HTTP headers
headers: {
// Learn about environment variables: https://gatsby.dev/env-vars
Authorization: `Bearer ${process.env.KL_TOKEN}`,},fetchOptions: {},
注:摘自https://www.gatsbyjs.com/plugins/gatsby-source-graphql/
直接在插件的高级选项中设置标题。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。