I am attaching a file to a blog post. The post can have many files. In this case, the post already exists and I am adding an extra file to it. I try specifying an existing UID and it does not like it.
mutationWriteNewFile := fmt.Sprintf(`
_:newfile <AttachedToBlogPost> "%s" .
_:newfile <FileName> "%s" .
_:newfile <MediaType> "image" .
_:newfile <created> "%s" .
_:newfile <updated> "%s" .
`, postUid, filename, timestamp, timestamp)
I have tried specifying the UID in different ways:
uid("%s")
uid(%s)
%s
"%s"
The results are always errors:
[ERROR] dgraph mutation: rpc error: code = Unknown desc = variables [0x3] not defined
[ERROR] dgraph mutation: rpc error: code = Unknown desc = variables ["0x3"] not defined
Invalid input: 0 at lexText
However, if I do the mutation as an upsert, by setting a variable beforehand, it works. Is this the only way to provide an existing UID to a new node in an nquad?
var(func: uid("%s")) {
postUid AS HasFiles
}
Schema for reference:
type BlogPost {
title
body
Files
created
updated
}
type File {
AttachedToBlogPost
FileName
MediaType
created
updated
}
title: string @index(term) .
body: string @index(fulltext) .
Files: [uid] .
FileName: string .
AttachedToBlogPost: uid @reverse .
MediaType: string .
created: datetime .
updated: datetime .