Using external id

upsert {
  query {
    q(func: eq(personName, "Lucas")) {
      v as uid
    }
  }

  mutation {
    set {
      uid(v) <Pets> _:NewPet .
      _:NewPet <petName> "Floky" .
    }
  }

For a existing pet in the DB.

upsert {
  query {
    q(func: eq(personName, "Lucas")) {
      v as uid
    }
    pet(func: eq(petName, "Floky")) {
      p as uid
    }
  }

  mutation {
    set {
      uid(v) <Pets> uid(p) .
    }
  }