JavaScript has the same issue
const dgraph = require("dgraph-js");
// Create a client stub.
function newClientStub() {
return new dgraph.DgraphClientStub("localhost:9080");
}
// Create a client.
function newClient(clientStub) {
return new dgraph.DgraphClient(clientStub);
}
// Create data using JSON.
async function createData(dgraphClient) {
// Create a new transaction.
const txn = dgraphClient.newTxn();
try {
// Create data.
const p = {
"query": "{ q(func: eq(containerId, 187263)) {v as uid} }",
"set": {
"containerId": "187263",
"name": "test",
"uid": "uid(v)"
}
};
// Run mutation.
const mu = new dgraph.Mutation();
mu.setSetJson(p);
const response = await txn.mutate(mu);
// Commit transaction.
await txn.commit();
response
.getUidsMap()
.forEach((uid, key) => console.log(`${key} => ${uid}`));
console.log();
} finally {
// Clean up. Calling this after txn.commit() is a no-op
// and hence safe.
await txn.discard();
}
}
async function main() {
const dgraphClientStub = newClientStub();
const dgraphClient = newClient(dgraphClientStub);
await createData(dgraphClient);
// Close the client stub.
dgraphClientStub.close();
}
main()
.then(() => {
console.log("\nDONE!");
})
.catch((e) => {
console.log("ERROR: ", e);
});
Error
code: 2,
details: 'variables [v] not defined',
metadata: Metadata {
internalRepr: Map(1) { 'content-type' => [Array] },
options: {}
}
}