You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Apollo CLI从Hasura端点下载GraphQL schema时报错如何解决?

问题排查与解决方案

根因分析

报错TypeError: is not a legal HTTP header name是由于Apollo CLI无法正确解析传入的--header参数,通常由Shell引号解析异常、参数包含多余不可见字符、header格式不符合CLI要求导致。

修复步骤

  • 调整命令的header参数写法,用双引号包裹完整的header键值对,同时用等号关联--header参数和值,避免Shell拆分参数:
apollo schema:download --header="X-Hasura-Admin-Secret: <替换为你的实际密钥>" --endpoint=https://sample-backend-for-hasura-tutorial.hasura.app/v1/graphql schema.json
  • 如果你使用的是Windows系统的CMD/PowerShell环境,单引号不会被Shell识别为参数包裹符,必须使用双引号,同时不要在参数前后添加多余的空格、换行等不可见字符。
  • 如果命令行传参始终报错,可以通过配置文件指定参数,在项目根目录新建apollo.config.js,写入以下内容:
module.exports = {
  client: {
    service: {
      name: "hasura-service",
      url: "https://sample-backend-for-hasura-tutorial.hasura.app/v1/graphql",
      headers: {
        "X-Hasura-Admin-Secret": "<替换为你的实际密钥>"
      }
    }
  }
};

之后直接执行简化命令即可:

apollo schema:download schema.json

内容的提问来源于stack exchange,提问作者maxweld

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.28 07:24:05