Skip to content

Support a new Upsert operation #3059

@manishrjain

Description

@manishrjain

This operation would allow a user to run a query, and use its results (via variables) to execute the mutation. This would then allow upserts to happen, without doing multiple network calls to the DB.

txn {
  query {
    me(func: eq(email, "someone@gmail.com")) {
      v as uid
    }
  }

  mutation @if(eq(len(v), 0)) {
    set {
      <uid(v)> <name> "Some One" .
      <uid(v)> <email> "someone@gmail.com" .
    }
  }
}

This txn would check for an account with email=someone@gmail.com, and only if it is present, would
it run the mutation.

This should return the result of query, normally. And also return the result of the mutation.

Additionally, we should be able to optionally do the mutation, iff the email is already present.

txn {
  query {
    me(func: eq(email, "someone@gmail.com")) {
      v as uid
    }
  }

  mutation @if(gt(len(v), 0)) {
    set {
      <uid(v)> <name> "Changed Name" .
    }
  }
}

This would introduce a new txn operator, and a new if directive applicable for mutations.

Metadata

Metadata

Assignees

Labels

kind/featureSomething completely new we should consider.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions