我有这些模型:
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 中建立的,当我查询所有用户但是当我对自定义用户使用这个自定义查询时,餐点被定义为 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"
}
]
}
]
}
}