1

I am beginner with dgraph and shifting from neo4j to dgraph. I am writing schema where I have different social media platforms details.

Considering facebook, the schema will have basic details of the profile,groups,pages plus different relations between the fb profiles and groups and pages like

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

Similar case for twitter where the relations will be

twitter_user 'follows' user_a
user_a 'followed_by' users

What I have done so for

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)  

    }

Kindly guide and correct me about schema structure. Looking forward to implement it in pydgraph

Thanks

Got help from https://tour.dgraph.io/schema/1/

I expect a schema that will accept the basic details and relations via python code

lczapski
  • 4,026
  • 3
  • 16
  • 32
Shahan Ali
  • 11
  • 1

1 Answers1

0

Based on the example you're referring to:

  • in your case neither should it be necessary to define an id field on a type, nor make it a type string. The dgraph will assign a uid automatically. The indexing by uid is much faster.
  • make sure to provide directives. For example, if you define a relation between a Person and a Page in the following way: likes : [Page] ., provide a directive of a form likes: [uid] . after your type definitions.

You could also consider trying a GraphQL version of the Dgraph, so you can build relationships with the GraphQL SDL, which would make them reusable in your app.

Artem
  • 33
  • 2
  • 7