【问题标题】:Is it possible to map Apollo GraphQL responses into a single type?是否可以将 Apollo GraphQL 响应映射为单一类型?
【发布时间】:2021-08-01 06:14:30
【问题描述】:

我有一些返回 Profile 对象的不同突变和查询。我想创建一个由所有这些不同调用实现的单一 Profile 对象,而不是调用命名空间下嵌套类型的默认 Apollo 行为。

现在:

SignInWithApple() -> SignInWithApple.Profile
SignInWithGoogle() -> SignInWithGoogle.Profile
SignInWithEmail() -> SignInWithEmail.Profile
GetProfile() -> GetProfile.Profile

希望:

SignInWithApple() -> Profile
SignInWithGoogle() -> Profile
SignInWithEmail() -> Profile
GetProfile() -> Profile

Edit* 到目前为止,我已经能够通过跳过 Apollo 生成的响应并将原始数据解码为我制作的 Profile 对象来完成此操作,但我仍然需要制作特殊的 DeCodable 容器,以便每个查询的命名空间/mutation 可以展开/删除。看来一定有更好的办法……

【问题讨论】:

    标签: ios graphql apollo


    【解决方案1】:

    您可以使用 Union Interfaces 创建一个 Profile 类型,可以是其中的任何一个。

    这样

    union Profile = SignInWithApple.Profile | 
      SignInWithGoogle.Profile |
      SignInWithEmail.Profile |
      GetProfile.Profile
    

    【讨论】:

      猜你喜欢
      • 2021-10-13
      • 1970-01-01
      • 2020-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-04
      • 2018-02-18
      相关资源
      最近更新 更多