Implementation
@override
FieldRefInput? get relatedJson {
var _byType = <String?, List<dynamic>>{};
for (var ref in _connect) {
var updates = _byType.putIfAbsent(ref._recordType, () => []);
if (ref._create != null) {
// final list = data.putIfAbsent('create', () => []) as List;
updates.add({
"create": {
"node": ref._create!.toJson(),
"edge": (ref._props!.toJson() as Object?)?.withoutKey('node'),
}
});
} else if (ref._linkedId != null) {
updates.add({
"connect": {
"where": {
"node": {"id": ref._linkedId!},
},
"edge": (ref._props!.toJson() as Object?)?.withoutKey('node'),
}
});
}
}
// final _createList = _connect.where((c) => c._create != null);
// final _createByType = <String?, List<C>>{};
// final _connectByType = <String?, List<String>>{};
// for (var item in _createList) {
// _createByType.putIfAbsent(item._recordType, () => []).add(item._create!);
// }
// final _connectList = _connect.where((c) => c._linkedId != null);
// for (var connect in _connectList) {
// _connectByType
// .putIfAbsent(connect._recordType, () => [])
// .add(connect._linkedId!);
// }
// if (_connect.isNotEmpty || _disconnect.isNotEmpty) {
// for (var ref in _connect) {
// if (ref._create != null) {
// final list = data.putIfAbsent('create', () => []) as List;
// list.add({
// "node": ref._create!.toJson(),
// "edge": (ref._props!.toJson() as Object?)?.withoutKey('node'),
// });
// } else if (ref._linkedId != null) {
// final list = data.putIfAbsent('connect', () => []) as List;
// list.add({
// "where": {
// "node": {"id": ref._linkedId!},
// },
// "edge": (ref._props!.toJson() as Object?)?.withoutKey('node'),
// });
// }
// }
// }
var types = _byType.keys;
if (types.length == 1 && types.first == null) {
return [
..._byType.values.first,
if (isReplace)
{
"disconnect": {
"where": {
"node": {
"id_NOT_IN": _connect
.map((e) => e._linkedId)
.whereType<String>()
.toList(),
}
}
},
}
];
} else {
if (isReplace) {
_byType.values.forEach((element) {
element.add({
"disconnect": {
"where": {
"node": {
"id_NOT_IN": _connect
.map((e) => e._linkedId)
.whereType<String>()
.toList(),
}
}
},
});
});
}
return _byType;
}
}