Implementation
@override
FieldRefInput? get relatedJson {
var data = <String, dynamic>{};
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'),
});
}
}
}
if (isReplace) {
data["disconnect"] = {
"where": {
"node": {
"id_NOT_IN": _connect.map((e) => e._linkedId)
.whereType<String>()
.toList(),
}
}
};
}
return data.isEmpty ? null : data;
}