Say I am having a data like:
fragment DataRecursive on DataModel {
id
parentId
children {
id
parentId
children {
id
parentId
// add more nesting if needed
}
}
}
query FetchData {
data {
dataGroup1 {
...DataRecursive
}
dataGroup2 {
...DataRecursive
}
}
}
Since the dart class is going to look something like:
class Data {
const Data({
required this.dataGroup1,
required this.dataGroup2,
});
factory Data.fromGraphQL(GFetchData data) {
return Data(
dataGroup1:
data.data.dataGroup1
?.map((c) => DataNode.fromJson(c.toJson()))
.toList() ??
[],
dataGroup2:
data.data.dataGroup2
?.map((r) => DataNode.fromJson(r.toJson()))
.toList() ??
[],
);
}
final List<DataNode> dataGroup1;
final List<DataNode> dataGroup2;
}
The question here is how to omit using fromJson(r.toJson()) to properly parse the data?
The issue is that there are different classes generated for each dataGroup
Say I am having a data like:
Since the dart class is going to look something like:
The question here is how to omit using
fromJson(r.toJson())to properly parse the data?The issue is that there are different classes generated for each
dataGroup