-1

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

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

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”非常模糊,我无法得到更详细的消息错误。

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

4

1 回答 1

0

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
  });
于 2021-10-15T20:35:34.010 回答