【问题标题】:How to flat query result?如何扁平化查询结果?
【发布时间】:2017-11-16 00:11:32
【问题描述】:

带样例让大家容易理解,带https://developer.github.com/v4/explorer/

查询观众信息:

query {
  viewer {
    followers {
      totalCount
    }
    following {
      totalCount
    }
  }
}

结果是:

{
  "data": {
    "viewer": {
      "followers": {
        "totalCount": 131
      },
      "following": {
        "totalCount": 28
      }
    }
  }
}

我想要的是:

{
  "data": {
    "viewer": {
      "followersCount" 131,
      "followingCount": 28
    }
  }
}

那么 GraphQL 支持这个吗?以及怎么做?

【问题讨论】:

    标签: graphql


    【解决方案1】:

    GraphQL 不支持这种类型的数据扁平化。
    您必须更改代码中的数据结构或使用返回的数据结构。


    编辑:我刚刚遇到this repository (graphql-lodash),它可以帮助你实现你想要的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-07-03
      • 1970-01-01
      • 2014-04-08
      • 2023-03-04
      • 2023-03-30
      • 1970-01-01
      • 2022-09-26
      相关资源
      最近更新 更多