Strawberry Shake使用gzip压缩遇JsonException,无法下载大Schema
解决Strawberry Shake CLI Schema下载的矛盾问题
针对你遇到的「加gzip头触发Json解析错误,不加又提示Schema过大」的问题,给你几个可行的解决思路:
方法一:手动下载并导入压缩后的Schema
CLI本身处理gzip响应存在bug,换手动方式绕开:
- 用curl请求带gzip压缩的Schema,保存为压缩文件:
curl -H "Accept-Encoding: gzip" -H "Authorization: Bearer eyJhbGciOiJIUzI1..." https://integrate.somecloud.com/graphql -X POST -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 } } } } } } }"}' --output schema.gz
- 解压
schema.gz得到schema.json文件 - 用本地Schema文件执行初始化命令:
dotnet graphql init ./schema.json -n SomeClient -p ./StrawberryShakeConsole --tokenEndpoint https://integrate.somecloud.com/auth --token eyJhbGciOiJIUzI1...
方法二:升级Strawberry Shake CLI
这个Json解析错误大概率是旧版本CLI不支持自动解压gzip响应导致的,尝试升级到最新版:
dotnet tool update StrawberryShake.Tools --global
升级后再重新执行原来带--headers Accept-Encoding=gzip的初始化命令。
方法三:精简Introspection Query(可选)
如果服务器允许,你可以修改Introspection Query,去掉一些非必要字段(比如废弃字段描述、某些类型细节),缩小响应体积,这样不用gzip也能下载。比如把includeDeprecated: true改成false,或者去掉deprecationReason字段,然后用curl请求后再导入本地文件。
内容的提问来源于stack exchange,提问作者Baxter
相关产品推荐
相关产品推荐

