Hello, I’m still very new to Dgraph, so I might be doing something completely wrong…
Basically I have the following schema:
board: uid @reverse .
title: string @index(term, fulltext) .
description: string .
author: uid @reverse .
username: string @index(exact) .
With a User and a Board struct:
type User struct {
Uid string `json:"uid,omitempty"`
Username string `json:"username,omitempty"`
}
type Board struct {
Uid string `json:"uid,omitempty"`
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
Author string `json:"author,omitempty"`
}
I then create a user like this:
var userForm struct {
Username string `json:"username"`
}
// unmarshal json from http.Request to userForm
resp, err := database.DgraphMutateSetJson(userForm)
if err != nil {
fmt.Println(err)
}
This works, and from resp.Uids["blank-0"]
I get whatever uid was generated, e.g. 0x4
.
The problem now is that I want to associate this author uid with whatever Board I create, e.g.:
var boardForm struct {
Title string `json:"title"`
Description string `json:"description"`
Author string `json:"author"`
}
// unmarshal json from http.Request to boardForm
resp, err := database.DgraphMutateSetJson(boardForm)
if err != nil {
fmt.Println(err)
}
However, this results in the error in the title (rpc error: code = Unknown desc = Input for predicate author of type uid is scalar
).
My POST request (that is unmarshalled to boardForm) include the following JSON:
{
"title":"My Title",
"description":"My Description",
"author":"0x4"
}
I’d greatly appreciate help about what I’m doing wrong (regarding the error), as well as tips about how I can improve my schema in order to associate a Board with a User, and a Post with a Board + a User, etc.