user1189332
user1189332

Reputation: 1941

DGraph simplest mutation using blank nodes

Just started with DGraph and trying to understand a simplest mutation. This is what I have:

{
 set {
_:james <personId> "jr123" .
_:james <stayed_at> "crowne_plaza" .
}
}

It created 2 nodes which was verified using:

{
  persons(func:eq(personId, "jr123")) {
  stayed_at
  }
}

My hope/expectation was to create a single person (node) of james and a single node of crowne_plaza with an edge representing "stayed_at".

What am I missing here?

Upvotes: 0

Views: 110

Answers (2)

Michel Conrado Diz
Michel Conrado Diz

Reputation: 321

This mutation is written wrong, despite the probability of you (or Ratel UID bug) are mutating twice. This mutation is using the same blank node for the two entities.

    {
     set {
       _:james <personId> "jr123" .
       _:james <stayed_at> _:plaza .
       _:plaza <name> "crowne_plaza" .
      }
    }

The query

{
  persons(func: eq(personId, "jr123")) {
    uid
    personId
    stayed_at {
          name
      }
    }
}

For more check this part of the tour https://tour.dgraph.io/master/intro/5/

Upvotes: 1

Daniel Mai
Daniel Mai

Reputation: 341

You're correct that the mutation would create a single node with two edges: personId and stayed_at`.

If you're using the Ratel UI, there's a nasty bug in the Local Bundle version where mutations are sent twice to Dgraph. This bug is fixed in the Latest and Dev distributions.

Upvotes: 0

Related Questions