Edge best practises re updating

Hey @damienburke,

I don’t think there should be any side-effect of repeatedly creating an edge.

Yes. You can do an upsert for edges. Consider the following example:

Let the data be as follows:

{
	set{
  	_:a <follows> _:b .
  	_:a <name> "alice" .
  	_:b <name> "bob" .
    _:c <name> "carl" .
  }
}

We can change the edge “alice follows bob” to “alice follows carl” by the following upsert:

upsert {
  query {
    q(func: eq(name, "alice")){
      u as uid
      follows {
        old as uid
      }
    }
    q2(func: eq(name, "carl")){
      v as uid
    }
  }
  mutation {
    set{
      uid(u) <follows> uid(v) .
    }
    delete {
      uid(u) <follows> uid(old) .
    }
  }
}

Yes. Consider the following example:

{
	set{
  	_:a <follows> _:b (since=2019-01-01) .
  	_:a <name> "alice" .
  	_:b <name> "bob" .
  }
}

We can change the date “since” to an updated date by the following upsert:

upsert {
  query {
    q(func: eq(name, "alice")){
      u as uid
      follows {
        f as uid
      }
    }
  }
  mutation {
    set{
      uid(u) <follows> uid(f) (since=2020-07-11) .
    }
  }
}

Feel free to shoot followup questions. Please mark it solved if this helps :slight_smile:

2 Likes