lambdas are basically serverless functions that you can trigger from your schema.
What I’m talking about is using GitHub - dgraph-io/dgraph-js: Official Dgraph JavaScript client or https://dgraph.io/docs/clients/go/ to interact with the API.
First you gotta add a schema to your instance.
Go to the schema section, and paste in this, and deploy it:
type Thing {
edge1: Thing!
edge2: Thing!
edge3: Thing!
}
Then you just want to create a script, so if you’re using dgraph-js
: (this is messy psuedo code)
const dgraph = require("dgraph-js");
const clientStub = dgraph.clientStubFromCloudEndpoint(
"https://frozen-mango.eu-central-1.aws.cloud.dgraph.io/graphql",
"<api-key>"
);
const dgraphClient = new dgraph.DgraphClient(clientStub);
// Find 3 random Things
const query = `query things($rand1: int, $rand2: int) {
things(func: type(Thing)) (first: $rand1, offset: $rand2) {
id
}
}`;
const vars = { $rand1: randomNumber(), $rand2: randomNumber() };
const res = await dgraphClient.newTxn().queryWithVars(query, vars);
const randomThings = res.getJson();
let threeRandomThingsIds = [];
threeRandomThings.push(randomThings.things[randomNumber()].id)
threeRandomThings.push(randomThings.things[randomNumber()].id)
threeRandomThings.push(randomThings.things[randomNumber()].id)
// Create data.
const thing = {
edge1: threeRandomThings[0]
edge2: threeRandomThings[1]
edge3: threeRandomThings[2]
};
// Run mutation.
[...Array(10000).keys()].forEach(_ => {
const mu = new dgraph.Mutation();
mu.setSetJson(p);
await txn.mutate(mu);
}