Dgraph raw upsert in javascript http client

Hey @amaster507

I just found that we can do this via dgraph-js-http.
After that conversation we had I went to see if I had done anything related to this. And I found it.
What I did was.

 const upsertString = ` upsert {
            query {
               .....
            }

            mutation  {
              delete {
                .....
              }
            }

            mutation  {
              set {
                .....
              }
            }
          }
      `;

await dgraph.mutate(upsertString); # This is my own method. Not related to dgraph-js-http
# Inside my method/class I did
try {
(...)
if ((typeof mutation !== 'object') && mutation.includes("upsert")) {
        const response = await txn.mutate({ mutation: mutation, commitNow: true });
        return response;
      }
(...)
      return response;
    } catch (e) {
      console.error('Error: ', e);
    } finally {
      await txn.discard();
    }

This works. I was using in some code of a customer(mine).

1 Like