如何为复杂数组定义 Graphql 类型

How to define the Graphql type for complex array

我对通过 Graphql return 为这个复杂数组定义正确的 return 类型感到头疼。 我也在使用 Nest.JS 框架。

这是我的数据:

[
 [ { Id: '1' }, [ [ { x: '01-02-2021', y: 12345 } ] ] ],
 [ { Id: '172' }, [ [Object], [Object] ] ],
 [ { Id: '173' }, 
  [
  [Object], [Object], [Object], [Object],[Object], [Object], [Object], [Object],
  [Object], [Object], [Object], [Object],[Object], [Object] 
  ]
 ]
]

这是 Class 我正在尝试 return 作为解析器的 [分组]。

@ObjectType()
export class Grouped {
  Id: string;
  SumPerDay: SumPerDay[];
}

@ObjectType()
class SumPerDay {
  x: string;
  y: number;
}

但是,returnid 和 SumPerday 都为 null。

欢迎对此提出任何想法!

我通过添加类型解决了它。

所以我没有返回上面的数组,而是将返回数据稍微更改为:

    "Grouped": [
  {
    "Id": "1",
    "_data": [
      {
        "x": "Thu Sep 30 2021",
        "y": 0.02
      }
    ]
  },
  {
    "Id": "172",
    "_data": [
      {
        "x": "Mon Oct 04 2021",
        "y": 2327.7599999999998
      },
      {
        "x": "Wed Oct 06 2021",
        "y": 172.91000000000003
      }
    ]
  },
]

现在可以使用了。