【问题标题】:Apollo GraphQL schema + codegen converting Hasura/PostgreSQL scalar array to scalarApollo GraphQL schema + codegen 将 Hasura/PostgreSQL 标量数组转换为标量
【发布时间】:2022-01-11 23:02:01
【问题描述】:

我正在使用 Hasura 为 PostgreSQL 表提供 GraphQL 接口。如果我有一个带有integer[] 列的表,则命令apollo schema:download 将生成一个schema.json,其中包含:

      {
        "name": "distances",
        "description": null,
        "type": {
          "kind": "SCALAR",
          "name": "_int4",
          "ofType": null
        },
        "defaultValue": null
      }

这是不幸的,因为它没有传达这个字段是一个数组的信息。自然,当我使用 apollo codegen:generate 时,类型要么变形为 String,要么只是 _int4,如果使用 --passthroughCustomScalars 标志。

有没有办法配置我的 graphql 服务器 (Hasura) 或 apollo CLI 以保留数组类型信息?

【问题讨论】:

    标签: graphql apollo hasura


    【解决方案1】:

    事实证明,_ 前缀已经可以作为数组类型的指示符。我不确定其他情况是否会导致类型名称_int4,但在我的用例中,我可以放心地假设int4 来自Integer,而_int4 来自Integer[]

    这样我可以使用--passthroughCustomScalars 并为我的Apollo SDK 提供类型别名,以将apollo codegen:generate_int4 输出识别为整数数组并定义适当的JSON 编码/解码方法。代码生成工具有点粗糙,但易于管理。

    【讨论】:

      猜你喜欢
      • 2019-09-29
      • 2012-02-18
      • 2021-01-10
      • 2020-04-30
      • 2018-09-27
      • 2020-07-23
      • 2019-07-30
      • 2020-04-20
      • 2019-03-15
      相关资源
      最近更新 更多