Basic schema design question

Hi!
[beginner question]

Looking into adding “tags” into my project as shown here
https://github.com/dgraph-io/graphoverflow/blob/master/schema.txt. (in my case “topics”)
Graphoverflow is a very nice example Michel showed me, yet I’m wondering why this structure is used:

Tags: uid @reverse .
Tag: uid @reverse .
Tag.text: string @index(hash) .

Specifically, wouldn’t it be more simple when you know each tag or topic will be unique and just do this:

Tags: uid @ reverse
Tag: string @index(hash) .

Why/When would I want to design the schema like shown in Graphoverflow?

I think my brain just switched back on again after writing this down. Would be it be because you want to attach more properties to the tag itself?

Tag.Text: string @index(hash) . #each tag needs a name
Tags: uid @reverse . #predicate for multiple tags
Tag: uid @reverse . #predicate for unique tag

ref: https://github.com/dgraph-io/graphoverflow/blob/master/app/client/src/queries/Tag.js
So the tag node would be like:

{
  "data": {
    "allTags": [
      {
        "uid": "0x1",
        "Tag.text": "Dev",
        "~Tags": [{ "uid": "0xa"}, {"uid": "0xf4"} ], #relates to several
        "~Tag": [{ "uid": "0x23"}, {"uid": "0x155"} ] #relates to unique
      },
      {
        "uid": "0x2",
        "Tag.text": "Test",
        "~Tags": [{ "uid": "0xa551"}, {"uid": "0xd45"} ],
        "~Tag": [{ "uid": "0x223"}, {"uid": "0xf32"} ]
      }
    ]
  }

So I suppose:

"<Tags>" is for that “post” that has more than one tag.
"<Tag>" is for that “post” that has chosen to have a single tag.

In this case “Dev” relates to several non-unique posts via “Tags”.
And “Dev” relates to unique via “Tag”.

The tags “Dev” and “Test” are unique, only the relations via “Tag and tags” that are different.

This is because each tag needs a name, but they are unique, only their relationships are not.

PS. This project is incomplete, though.

That makes sense, I understand why it was done like that now. Also to help find the most relevant co-occurences of the tags e.g. to display “related tags”

1 Like