Two way relation not appearing, after DQL insert

I’m using the JS grpc library.

My schema as follows:

type GroupChatMessage @withSubscription {
  id: ID!
  xid: String! @id
  body: String!
  ...

  # ... relations
  ...
  reaction: [GroupChatMessageReaction]!
}

type GroupChatMessageReaction @withSubscription {
  id: ID!
  xid: String! @id
  ...

  # ... relations
  message: GroupChatMessage! @hasInverse(field: reaction)
  ...
}

My upsert:

query {
    message as var(func: eq(GroupChatMessage.xid, "${data.messageId}"))
    fromUser as var(func: eq(GroupChatUser.xid, "${data.fromId}"))
}

nQuads:
_:reaction <GroupChatMessageReaction.xid> "${data.id}" .
_:reaction <GroupChatMessageReaction.emoji> "${data.emoji}" .
_:reaction <GroupChatMessageReaction.image> "${data.image}" .
_:reaction <GroupChatMessageReaction.message> uid(message) .
_:reaction <GroupChatMessageReaction.fromUser> uid(fromUser) .
_:reaction <dgraph.type> "GroupChatMessageReaction" .

I see data in the GroupMessageReaction type when I query it

"data": {
    "queryGroupChatMessageReaction": [
      {
        "xid": "01FSCKZ08BSA29BNXQFY7VD2SC",
        "emoji": "star-struck",
        "image": "1f929",
        "message": {
          "xid": "01FQBQ4KPW0EGKAN3JBXFS0C15",
          "body": "{\"type\":\"doc\",\"content\":[{\"type\":\"paragraph\",\"content\":[{\"type\":\"text\",\"text\":\"yo\"}]}]}"
        },
        "fromUser": {
          "user": {
            "firstName": "Paul",

Problem is, when I do a query:

message {
  reaction {
      xid
        emoji
        image
    }
}

Reactions are empty:

"body": "{\"type\":\"doc\",\"content\":[{\"type\":\"paragraph\",\"content\":[{\"type\":\"text\",\"text\":\"yo\"}]}]}",
            "fromUser": {
              "xid": "01fkg0ts26wyj27bg66p5trb2h",
              "user": {
                "xid": "01FKG0S6G7QJ0W0HT4G5Y5EKEM",
                "firstName": "Betsy",
                "lastName": "Voss"
              }
            },
            "replyMessage": null,
            "thread": null,
            "reaction": [],

So I thought about adding to my nQuad above, to try and close the loop:

uid(_:reaction) <GroupChatMessage.reaction> uid(message) .

But I get the following:

Do request:
{"startTs":0,"query":"\n\t\tquery {\n\t\t\tmessage as var(func: eq(GroupChatMessage.xid, \"01FQBQ4KPW0EGKAN3JBXFS0C15\"))\n\t\t\tfromUser as var(func: eq(GroupChatUser.xid, \"01fk63kskdyd4ggge5c5ehkn3y\"))\n\t\t}\n\t","varsMap":[],"readOnly":false,"bestEffort":false,"mutationsList":[{"setJson":"","deleteJson":"","setNquads":"CgkJXzpyZWFjdGlvbiA8R3JvdXBDaGF0TWVzc2FnZVJlYWN0aW9uLnhpZD4gIjAxRlNDS1k5VkQwM1lLMjQ3VE4yTThXWjdUIiAuCgkJXzpyZWFjdGlvbiA8R3JvdXBDaGF0TWVzc2FnZVJlYWN0aW9uLmVtb2ppPiAic3R1Y2tfb3V0X3Rvbmd1ZSIgLgoJCV86cmVhY3Rpb24gPEdyb3VwQ2hhdE1lc3NhZ2VSZWFjdGlvbi5pbWFnZT4gIjFmNjFiIiAuCgkJXzpyZWFjdGlvbiA8R3JvdXBDaGF0TWVzc2FnZVJlYWN0aW9uLm1lc3NhZ2U+IHVpZChtZXNzYWdlKSAuCgkJXzpyZWFjdGlvbiA8R3JvdXBDaGF0TWVzc2FnZVJlYWN0aW9uLmZyb21Vc2VyPiB1aWQoZnJvbVVzZXIpIC4KCQlfOnJlYWN0aW9uIDxkZ3JhcGgudHlwZT4gIkdyb3VwQ2hhdE1lc3NhZ2VSZWFjdGlvbiIgLgoKCQl1aWQoXzpyZWFjdGlvbikgPEdyb3VwQ2hhdE1lc3NhZ2UucmVhY3Rpb24+IHVpZChtZXNzYWdlKSAuCgk=","delNquads":"","setList":[],"delList":[],"cond":"","commitNow":false}],"commitNow":true,"respFormat":0,"hash":""}
/Users/paul/Share/development/app_api/node_modules/@grpc/grpc-js/build/src/call.js:31
    return Object.assign(new Error(message), status);
                         ^

Error: 2 UNKNOWN: Some variables are used but not defined
Defined:[fromUser message]
Used:[_:reaction fromUser message]

    at Object.callErrorFromStatus (/Users/paul/Share/development/app_api/node_modules/@grpc/grpc-js/build/src/call.js:31:26)
    at Object.onReceiveStatus (/Users/paul/Share/development/app_api/node_modules/@grpc/grpc-js/build/src/client.js:180:52)
    at Object.onReceiveStatus (/Users/paul/Share/development/app_api/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:365:141)
    at Object.onReceiveStatus (/Users/paul/Share/development/app_api/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:328:181)
    at /Users/paul/Share/development/app_api/node_modules/@grpc/grpc-js/build/src/call-stream.js:182:78
    at processTicksAndRejections (node:internal/process/task_queues:78:11) {
  code: 2,
  details: 'Some variables are used but not defined\n' +
    'Defined:[fromUser message]\n' +
    'Used:[_:reaction fromUser message]\n',
  metadata: Metadata {
    internalRepr: Map(1) { 'content-type' => [ 'application/grpc' ] },
    options: {}
  }
}

If someone can point out what I’m missing, really appreciative.

Thanks!

Not sure what you are doing here. But this uid param doesn’t support blank nodes, only variables.

Thanks for the reply.

I was attempting to make an edge the other way. I saw another discuss post with this and didn’t know if it was valid or not.

Now that you have confirmed it needs a variable.

Is it possible to retrieve the newly created uid for the GroupChatMessageReaction type within the upsert?

If it is in the same transaction you can simply use the Blank Node. If it is a new transaction, you have to query for the target and then use it in a variable.

Thanks for mentioning blank node. That pinged something in my memory :laughing:

uid(message) <GroupChatMessage.reaction> _:reaction .

Solved it for me.

Many thanks

1 Like