【问题标题】:Is is possible to get a property defined in one schema type and get it in other schema type in graphql是否可以获取在一种模式类型中定义的属性并在 graphql 中以其他模式类型获取它
【发布时间】:2022-06-14 22:33:25
【问题描述】:

我有一个看起来像这样的架构。

exports.typeDefs = gql`
type User {
   userid: ID!
   name: String
}

type Post {
   post_id: ID!
   post_category: String!
   post_type: String!
   post_hashtag: String
   user: User
 }

type query {
    post_hashtag: String
           @cypher[statement: "MATCH (n:Test_Temp) RETURN n.post_hashtag"]
 }
 `;

现在帖子有名为“post_hashtag”的字段。 我想定义另一种模式类型并获取所有节点的 post_hashtag 属性 帖子。

示例:如果我查询

query{
    hashtag{
       post_hashtag
    }
}

这应该给出任何帖子节点中可用的所有主题标签。

这几天我一直在尝试。经历了不同的解决方案,但都没有奏效。

【问题讨论】:

    标签: graphql schema


    【解决方案1】:

    我已经找到了问题所在。实际上我们只需要使用neo4j 的collect 方法返回一个hashtags 数组并保存在hashtag 节点中。它将保存节点上的所有主题标签,我们可以稍后检索它。

    只是密码查询将被下面的更改。

    MATCH (n:Test_Temp) RETURN collect(n.post_hashtag)
    

    【讨论】:

      猜你喜欢
      • 2019-01-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-09
      • 2020-09-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多