Parsing UID objects in DGraphjs when creating relations

Hey all,

I’ve been trying to modify an entry using a mutation where the field I am trying to update is the UID field. I’m currently working with the dgraphjs with grpc. The current structure I have is this:

            const mutationBase = {
                uid: entryID,
                answer_paths: relationID,
            };

where relationID is something like 0xc1. I keep getting the following error being thrown. I’m not entirely sure what is needed here to fix this. It looks to me like dgraphjs needs a specific type of data for this fiend, which, in the schema is defined as [uid] type. What is the correct way to parse a UID here? The weird part is that the entryID does not throw this error.

What error?

Not sure what is happening to your case. The UID field can be just a string. There’s no especial type in JavaScript for uint64.

So you are trying to update the child of “entryID”. Which looks like a question → answer relation. You said that the type is one to many ([uid]). If you are adding a new relation your mutation should look like this:

            const mutationBase = {
                uid: entryID,
                answer_paths: { uid: relationID }
            };

If you wanna update it, you have to delete the old relation and add this new one.

1 Like

Thanks for taking a look at this. I realized what the issue here is. I was constructing the request improperly, it has nothing to do with types (well, not really). I ended up scanning through the example and inferring that I needed to design the mutation a little differently. I put together this as my updated request:

            const mutationBase = {
                uid: entryID,
                question_text: 'I have Updated',
                answer_paths: {
                    uid: relationID
                },
            };

I put the I have Updated there just to verify that something happened…

Reading your answer, that’s exactly what you said also.

To actually answer your first question, the error itself was:

details: 'Input for predicate "answer_paths" of type uid is scalar. Edge: entity:192 attr:"answer_paths" value:"0xc1" value_type:STRING '

The note that you made about updates needing to delete the old relation is important, and will be very helpful later on. Thanks!

Got it. That’s a common mistake. So, you’re new to Dgraph. Be welcome!

This error comes from Dgraph itself. Not sure if it is clear to users, but don’t confuse those errors with the language you are running. This error is trying to say to you that the key you are inserting isn’t a string in Dgraph. But a Scalar UID. Maybe we should improve these logs.

The log logic is like: “What it is on DB and What it got from you”.

Cheers.

2 Likes