I am having a headache about defining the correct return types for this complex array I am returning via Graphql. I am also using the Nest.JS framework.
Here is my data:
[
[ { 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]
]
]
]
This is the Class I am trying to return, as [ Grouped ] for the resolver.
@ObjectType()
export class Grouped {
Id: string;
SumPerDay: SumPerDay[];
}
@ObjectType()
class SumPerDay {
x: string;
y: number;
}
This is however, returning null for both id and SumPerday.
Any thoughts about this would be welcome!
I solved it by adding the types.
So instead of returning the above array, I slightly changed the returning data into :
"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
}
]
},
]
Now it is working.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.