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

apollo-codegen introspect-schema突发报错及Apollo CLI证书问题求助

解决apollo-codegen Schema自省报错及Apollo CLI自签名证书问题

apollo-codegen 报「Errors in introspection query result: [object Object]」的处理方案

  • 抓取详细错误信息:默认报错仅显示[object Object],添加--verbose参数或设置DEBUG环境变量,可获取具体错误详情:
    DEBUG=apollo-codegen:* apollo-codegen introspect-schema https://localhost:4000/graphql --insecure --output schema.json
    
  • 强制跳过证书验证:部分环境下--insecure参数不生效,可通过node环境变量强制关闭证书校验:
    NODE_TLS_REJECT_UNAUTHORIZED=0 apollo-codegen introspect-schema https://localhost:4000/graphql --output schema.json
    
  • 验证服务器返回:用curl直接请求自省接口,确认服务器是否能正常返回数据(排除服务器端问题):
    curl -k https://localhost:4000/graphql -H "Content-Type: application/json" -d '{"query":"query IntrospectionQuery { __schema { queryType { name } mutationType { name } subscriptionType { name } types { ...FullType } directives { name description locations args { ...InputValue } } } } fragment FullType on __Type { kind name description fields(includeDeprecated: true) { name description args { ...InputValue } type { ...TypeRef } isDeprecated deprecationReason } inputFields { ...InputValue } interfaces { ...TypeRef } enumValues(includeDeprecated: true) { name description isDeprecated deprecationReason } possibleTypes { ...TypeRef } } fragment InputValue on __InputValue { name description type { ...TypeRef } defaultValue } fragment TypeRef on __Type { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name } } } } } } } }"}'
    

Apollo CLI -k flag不生效的替代方案

  • 使用--tls-accept-unauthorized参数:部分Apollo CLI版本中,该参数替代了-k来处理自签名证书:
    apollo schema:download --endpoint=https://localhost:4000/graphql --tls-accept-unauthorized schema.json
    
  • 用环境变量跳过校验:同样借助NODE_TLS_REJECT_UNAUTHORIZED强制忽略证书问题:
    NODE_TLS_REJECT_UNAUTHORIZED=0 apollo schema:download --endpoint=https://localhost:4000/graphql schema.json
    
  • 手动指定证书文件:如果有服务器自签名证书文件,通过--cert参数指定路径:
    apollo schema:download --endpoint=https://localhost:4000/graphql --cert=./path/to/your-cert.crt schema.json
    

社区反馈的类似问题

不少用户在社区讨论中遇到过相同情况,主要诱因包括:node版本更新后证书验证逻辑变更、apollo工具版本兼容性问题、本地代理拦截请求。如果上述方法都无效,可以尝试降级node到之前能正常运行的版本,或者换用graphql-cli工具完成自省:

graphql get-schema -e https://localhost:4000/graphql --no-ssl-verify

内容的提问来源于stack exchange,提问作者Javier salvaña

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.12 22:10:26