我有这些模型:
type User {
userId: ID!
mail: String!
password: String! @private
meals: [Meal!] @relationship(type: "IN_MEALS", direction: OUT)
}
type Meal {
name: String!
createdBy: User! @relationship(type: "IN_MEALS", direction: IN)
}关系是在neo4j中建立的,当我查询所有用户时,但是当我对自定义用户使用这个自定义查询时,meals被定义为null我不知道为什么
type Query {
currentUser: User
@cypher(
statement: """
MATCH (u:User {userId: $auth.jwt.userId})
OPTIONAL MATCH (u)-[r:IN_MEALS]->(m:Meal)
RETURN u,r,m
"""
)
}当我在graphql中执行此查询时
{
currentUser {
userId
mail
meals {
name
}
}
}它告诉我饭菜是无效的,但它们不是...
{
"data": {
"currentUser": {
"userId": "02e7b50a-1a51-4d3b-b26b-57ed08d89c5a",
"mail": "mak@gmail.com",
"meals": null
}
}
}通过查看我的neo4j数据库,我知道了这一点,这也是因为当我查询所有用户时
{
users {
mail
meals {
name
}
}
}我可以在餐饮中看到这些价值:
{
"data": {
"users": [
{
"mail": "mak@gmail.com",
"meals": [
{
"name": "frites"
},
{
"name": "mcdo"
},
{
"name": "sushi"
}
]
}
]
}
}发布于 2021-10-30 12:02:21
据我所知,你只需要提供toplevel节点,然后宏堆栈将处理获取额外的关系等。不幸的是,documentation似乎不是那么清楚。尝试使用:
type Query {
currentUser: User
@cypher(
statement: """
MATCH (u:User {userId: $auth.jwt.userId})
RETURN u
"""
)
}https://stackoverflow.com/questions/69775011
复制相似问题