微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

我可以将关系作为节点内的字段返回吗?

如何解决我可以将关系作为节点内的字段返回吗?

我目前有这个查询

OPTIONAL MATCH (t)<-[r:CHILD_OF]-(t1:Thing)<-[:TAGGED]-(post:Post)

后来我有

OPTIONAL MATCH (this)<-[:TAGGED]-(post:Post)

并且因为它们都一起返回(作为帖子列表),我不知道哪些帖子是事物的子级,或者哪些只是直接标记了“这个”。

这里的“CHILD_OF”关系变量名“r”存在时是否可以返回?

完整的帖子看起来像这样:

OPTIONAL MATCH (this)<-[:CHILD_OF]-(t1:Thing)<-[:TAGGED]-(post:Post)
WITH COLLECT(post) as rows,this
OPTIONAL MATCH (this)<-[:TAGGED]-(p:Post)
WITH rows + COLLECT(p) as allRows
UNWIND allRows as post
RETURN disTINCT post
ORDER BY post.date DESC

我不希望它作为地图,因为 neo4j-graphql-js 不支持它,它们只支持返回单个节点。所以我也不能做回帖,r

type Thing {
    id: ID!,name: String,description: String,image: String,followers: [User] @relation(name: "FOLLOWS",direction: "IN"),posts: [Post] @cypher(statement: """
        OPTIONAL MATCH (this)<-[:CHILD_OF]-(t1:Thing)<-[:TAGGED]-(post:Post)
        WITH COLLECT(post) as rows,this
        OPTIONAL MATCH (this)<-[:TAGGED]-(p:Post)
        WITH rows + COLLECT(p) as allRows
        UNWIND allRows as post
        RETURN disTINCT post
        ORDER BY post.date DESC
    """)
   
}

type User {
    id: ID!,uid: String,email: String,bio: String,direction: "OUT"),post_count: Int @cypher(statement: """
        MATCH (this)-[:WROTE]->(p:Post)
        RETURN count(p)
    """),homepage_posts: [Post] @cypher(statement: """
        OPTIONAL MATCH (this)-[r:FOLLOWS]->(something)-[:WROTE|TAGGED]-(post:Post)        
        WITH COLLECT(post) as rows
        OPTIONAL MATCH (this)-[:WROTE]->(post:Post)
        WITH rows + COLLECT(post) as allRows
        UNWIND allRows as post
        RETURN disTINCT post
        ORDER BY post.date DESC
    """)
}

type Relationship {
    type: String
}

type Post {
    id: ID!,body: String,images: [String],date: DateTime,isRetweet: Boolean,rating: Float,relationship: Relationship,author: User @relation(name: "WROTE",things: [Thing] @relation(name: "TAGGED",likes: [User] @cypher(statement: """
        MATCH (u:User)-[r:LIKES]->(this)
        RETURN u
    """),}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。