Dgraph raw upsert in javascript http client

This error happens when using Dgraph-JS, switch to Dgraph-JS-http.
There is no gRPC in the HTTP client.

Here is a complete copy of the class.
Pay attention that this is a custom stuff. It needs improvement.

import { DgraphClient, DgraphClientStub} from 'dgraph-js-http';

class DgraphService {
  constructor() {
    const stub = new DgraphClientStub('http://192.168.9.163:8081/');
    this.client = new DgraphClient(stub);
  }

  async query(q) {
    const response = await this.client.newTxn().query(q);
    return response.data;
  }

  async mutate(mutation) {
    const txn = this.client.newTxn();

    try {
      if ((typeof mutation !== 'object') && mutation.includes("upsert")) {
        const response = await txn.mutate({ mutation: mutation, commitNow: true });
        return response;
      }
      if (typeof mutation == 'object') {
        const response = await txn.mutate({ setJson: mutation, commitNow: true });
        return response;
      }
      const response = await txn.mutate({ setNquads: mutation });
      await txn.commit();
      return response;
    } catch (e) {
      console.error('Error: ', e);
    } finally {
      await txn.discard();
    }
  }
  
}

export default new DgraphService();