【发布时间】:2021-07-03 11:12:21
【问题描述】:
我有节点 user 和 game 以及它们之间的一些关系。
我的 REST API 应该返回游戏和 1 个用户之间的所有关系。
我使用的密码查询是:
MATCH (u:User {id: '1234'} ) -[rel]- (game:Game) return game{.*, relationships: collect(DISTINCT rel)}
在我的 Neo4j 浏览器中,一切正常,我看到了我需要的所有属性。 但是 GetMapping 会返回除关系属性之外的所有内容。
Neo4j 浏览器
{
"relationships": [
{
"identity": 54,
"start": 9,
"end": 8,
"type": "OWNED",
"properties": {
"ownedDate": "2021-07-03"
}
},
{
"identity": 45,
"start": 9,
"end": 8,
"type": "PLAYED",
"properties": {
"times": 5
}
}
],
"name": "Blood Rage",
"state": "ACTIVE",
"id": "1c152c91-4044-41f0-9208-0c436d6f6480",
"gameUrl": "https://asmodee.de/blood-rage"
}
GetMapping 结果(如您所见,关系为空,但当有更多关系时,我有更多空的 JsonObjects
{
"game": {
"relationships": [
{},
{}
],
"name": "Blood Rage",
"gameUrl": "https://asmodee.de/blood-rage",
"state": "ACTIVE",
"id": "1c152c91-4044-41f0-9208-0c436d6f6480"
}
}
GetMapping 是:
...
final ReactiveNeo4jClient client;
...
...
...
@GetMapping(value = { "/{id}/games"})
@RolesAllowed({"user", "admin"})
Flux<Map<String, Object>> findGamesByUser(@PathVariable String id){
String query = "MATCH (uuser:User {id: '" + id + "'} ) -[rel]- (game:Game) return game{.*, relationships: collect(DISTINCT rel)}";
return client.query(query).fetch().all();
}
关系属性示例
@RelationshipProperties
@Data
@Builder
public class PlayedGame {
@Id
@GeneratedValue
private Long relationshipId;
@Property
int times = 0;
@TargetNode private GameEntity game;
public int addPlay(){
this.times = this.times + 1;
return this.times;
}
}
我必须在 GetMapping 中进行哪些更改才能显示关系属性?
谢谢你, 凯文
【问题讨论】:
标签: neo4j cypher spring-webflux spring-data-neo4j