【问题标题】:How to query relationships of neo4j with custom query with cypher using Grandstack?如何使用 Grandstack 使用带有密码的自定义查询来查询 Neo4j 的关系?
【发布时间】:2021-10-30 21:42:48
【问题描述】:

我有这些模型:

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"
          }
        ]
      }
    ]
  }
}

【问题讨论】:

    标签: neo4j graphql cypher grandstack


    【解决方案1】:

    据我了解,您只需要提供顶级节点,然后 GRAND 堆栈将处理获取其他关系等。不幸的是,documentation 似乎不太清楚。尝试使用:

    type Query {
      currentUser: User
        @cypher(
          statement: """
          MATCH (u:User {userId: $auth.jwt.userId})
          RETURN u  
          """
        )
    }
    

    【讨论】:

    • 谢谢!但是 yhat 正是我一开始所拥有的,它也不起作用......我有“饭菜”:null 但是当我查看我的图表或查询所有用户时,我可以看到该用户的饭菜不是空的
    • 但是你得到了用户ID?
    • 是的,我得到了所有其他信息,我编辑了我的帖子,所以你可以看到
    • 这看起来像一个错误,我会直接向 GH 报告。
    • 好的,谢谢! :)
    猜你喜欢
    • 1970-01-01
    • 2012-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-05
    相关资源
    最近更新 更多