【问题标题】:Source GraphQL API: HTTP error 400 Bad Request源 GraphQL API:HTTP 错误 400 错误请求
【发布时间】:2021-12-03 23:32:16
【问题描述】:

我已经建立了一个可通过网关访问的阿波罗联盟架构。我想通过 gatsby 使用官方插件gatsby-source-graphql 访问它。我遵循了他们的文档并尝试将插件包含在“简单”示例中。

当我在我的 gatsby 项目上运行 yarn build 时,我得到以下终端输出:

success onPreInit - 0.048s
success initialize cache - 0.033s
success copy gatsby files - 0.139s
success Compiling Gatsby Functions - 0.239s
success onPreBootstrap - 0.258s
success createSchemaCustomization - 0.003s

 ERROR #11321  PLUGIN

"gatsby-source-graphql" threw an error while running the sourceNodes lifecycle:

Source GraphQL API: HTTP error 400 Bad Request



  Error: Source GraphQL API: HTTP error 400 Bad Request

  - fetch.js:11 exports.fetchWrapper
    [yotee.co]/[gatsby-source-graphql]/fetch.js:11:11

  - task_queues:96 processTicksAndRejections
    node:internal/process/task_queues:96:5

我的 gatsby-config.js 是这样的:

module.exports = {
  siteMetadata: {
    url: "https://www.XXXX.co",
    title: "XXXX",
    description: "",
    
  },
  plugins: [
    {
      resolve: 'gatsby-source-graphql',
      options: {
        typeName: 'Gateway',
        fieldName: 'gateway',
        url: 'https://XXXXXX'
      }
    },
    "gatsby-plugin-styled-components", 
    "gatsby-plugin-gatsby-cloud", 
    "@chakra-ui/gatsby-plugin",
    "gatsby-plugin-react-helmet"
  ],

};

错误“Source GraphQL API: HTTP error 400 Bad Request”非常模糊,我无法得到更详细的消息错误。

我可以做些什么来更好地理解这个错误并解决它?

【问题讨论】:

  • 这个 API 是否工作,没有身份验证的内省查询?用邮递员/失眠症测试?
  • 是的,服务器没有自省功能,不需要身份验证,是的,它可以与邮递员一起使用。

标签: graphql gatsby apollo-server gatsby-plugin apollo-federation


【解决方案1】:

gatsby 插件将尝试从您的 apollo-server 检索模式。确保在生产中启用自省,以免此步骤失败。

{"extensions":{"code":"GRAPHQL_VALIDATION_FAILED"},"level":"warn","locations":[{"column":3,"line":2}],"message":"GraphQL introspection is not allowed by Apollo Server, but the query contained __schema or __type. To enable introspection, pass introspection: true to ApolloServer in production"} 

作者:

  const server = new ApolloServer({
     // other properties
    introspection: true
  });

【讨论】:

  • 能否请您与我分享您的 gatsby-config.js 文件。我也有同样的问题,但是不知道ApolloServer代码放在哪里,怎么调用...
猜你喜欢
  • 2017-12-11
  • 2017-08-04
  • 1970-01-01
  • 1970-01-01
  • 2020-01-15
  • 1970-01-01
  • 1970-01-01
  • 2019-11-05
  • 2018-06-22
相关资源
最近更新 更多