![](/img/trans.png)
[英]How to define an Array datatype for GraphQL field in Type definition
[英]How to define the Graphql type for complex array
我对为我通过 Graphql 返回的这个复杂数组定义正确的返回类型感到头疼。 我也在使用 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]
]
]
]
这是我试图返回的类,作为解析器的 [ 分组 ]。
@ObjectType()
export class Grouped {
Id: string;
SumPerDay: SumPerDay[];
}
@ObjectType()
class SumPerDay {
x: string;
y: number;
}
然而,这对于 id 和 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
}
]
},
]
现在它正在工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.