【问题标题】:In GraphQL, can you change the structure of the output in an alias?在 GraphQL 中,您可以更改别名中的输出结构吗?
【发布时间】:2020-06-19 00:35:46
【问题描述】:

假设我有一个如下所示的 GraphQL 查询:

query {
  Todo {
    label
    is_completed
    id
  }
}

但是使用来自这个查询的数据的客户端需要一个有点不同的数据结构——例如一个 TypeScript 接口,例如:

interface Todo {
  title: string  // "title" is just a different name for "label"
  data: {
    is_completed: boolean
    id: number
  }
}

只需使用别名即可将label 作为title 返回。但是有没有办法让它在名为data 的别名下同时返回is_completedid

【问题讨论】:

标签: graphql


【解决方案1】:

没有办法做到这一点。要么更改架构以反映客户端的需求,要么在客户端获取响应后转换响应。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-29
    • 1970-01-01
    • 2012-11-02
    • 2015-08-27
    • 2019-10-20
    相关资源
    最近更新 更多