【问题标题】:Writing Social media's schema in dgraph在 dgraph 中编写社交媒体的模式
【发布时间】:2020-03-04 19:29:19
【问题描述】:

我是 dgraph 的初学者,并从 neo4j 转移到 dgraph。我正在编写架构,其中我有不同的社交媒体平台详细信息。

考虑到 facebook,架构将包含个人资料、群组、页面的基本详细信息,以及 fb 个人资料与群组和页面之间的不同关系,例如

profile_a is 'friends_of' profile_b;
user 'likes' page_b;
user is 'member_of' group_a
user 'works_at' place_a

关系将是 twitter 的类似情况

twitter_user 'follows' user_a
user_a 'followed_by' users

我这样做是为了什么

type Person{
        name: string @index(exact) .
        id: string @index(exact) .
        profile: string @index(exact) .
        picture_link: string .
        status_count: int .
        location: string .
        tags: string .
        user_id: int .
        follower_count: string .
        friend_count: string .
        type: int @index(exact) .   
        likes : [Page] .
        friends_of : [Fb_User] .
        members_of : [Group] .
        works_at : {
            name: string .
        }      
    }

    type Fb_User{
        name: string @index(exact) .
        id: string @index(exact) .
        profile: string @index(exact) .
        picture_link: string .
        status_count: int .
        location: string .
        type: int @index(exact) .  
        location: string .   
        tags: string .
        user_id: int .
    }

    type Group{
        name: string @index(exact) .
        id: string @index(exact) .
        profile: string @index(exact) .
        picture_link: string .
        group_member : int .

    }

    type Page{
        name: string @index(exact) .
        id: string @index(exact) .
        profile: string @index(exact) .
        picture_link: string .
        page_type : int .

    }

    type Facebook
     {  
        label: string @index(exact)  

    }

请指导和纠正我的架构结构。期待在pydgraph中实现它

谢谢

得到帮助 https://tour.dgraph.io/schema/1/

我希望架构能够通过 python 代码接受基本细节和关系

【问题讨论】:

    标签: python graph graphql dgraph


    【解决方案1】:

    基于您所指的example

    • 在您的情况下,既不需要在类型上定义id 字段,也不需要将其设为string 类型。 dgraph 将自动分配uiduid 的索引要快得多。
    • 确保提供指令。例如,如果您通过以下方式定义 PersonPage 之间的关系:likes : [Page] .,请在类型定义后提供 likes: [uid] . 形式的指令。

    您还可以考虑尝试使用 Dgraph 的GraphQL version,这样您就可以与 GraphQL SDL 建立关系,这将使它们在您的应用程序中可重用。

    【讨论】:

      猜你喜欢
      • 2018-08-28
      • 2014-10-12
      • 2020-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-03
      • 2014-02-24
      • 1970-01-01
      相关资源
      最近更新 更多