【问题标题】:How do I use Hasura/postgres uuid with apollo-ios and swift如何将 Hasura/postgres uuid 与 apollo-ios 和 swift 一起使用
【发布时间】:2020-04-10 12:40:30
【问题描述】:

我在 Hasura (Postgres) 中使用原生 uuid 作为字段数据类型定义了一个表。我的目标是从 Swift 创建一个更新突变,但 uuid 类型并没有从 Postgres 通过 Hasura 和 Apollo 隐式映射到 Swift。 Hasura 文档指出 uuid 类型支持使用String,但是当我在更新突变中定义变量时,将其定义为String!

mutation RedeemMagicLinkCode($code: String!, $iosIdentifierForVendor: String!) {
  __typename
  update_entityname(where: {code: {_eq: $code}, iosIdentifierForVendor: {_is_null: true}}, _set: {iosIdentifierForVendor: $iosIdentifierForVendor}) {
    returning {
      id
    }
  }
}

我从 Variable "$code" of type "String!" used in position expecting type "uuid". 的 Apollo 代码生成步骤中得到一个错误。当我将其更改为 uuid! 时,


mutation RedeemMagicLinkCode($code: uuid!, $iosIdentifierForVendor: uuid!) {
  __typename
  update_en...

代码生成步骤完成,生成 API.swift,但出现了几个编译错误 Use of undeclared type 'uuid' 的实例,现在由于 Apollo 生成的 API.swift 编译过程中出现故障。

/// API.swift
...
public let operationName = "RedeemMagicLinkCode"

  public var code: uuid
  public var iosIdentifierForVendor: uuid
...

谁能指出我正确的方向,让 Swift 知道什么是 uuid 或定义我的查询,以便我可以通过 Apollo 管理的突变将字符串作为参数传递?非常感谢!

【问题讨论】:

    标签: swift hasura apollo-ios


    【解决方案1】:

    OM(天哪),我可能需要为这个解决方案如此简单而脸红。

    我考虑了错误 Use of undeclared type 'uuid' 以及 Hasura 将为此自定义标量接受 String 的文档...

    /// API+typealias.swift
    public typealias uuid = String
    

    我将上述类型别名代码单独放在我的 GraphQL 文件所在的文件夹中的一个文件中,瞧,效果很好!

    我对这个现在在全球范围内使用的公共类型别名并不感到兴奋,但我对工作数据服务感到兴奋

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-31
      • 2012-11-01
      • 2018-09-05
      • 2016-02-10
      • 2021-01-11
      • 2018-11-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多