Trying to delete from query result in dgraph-js

I’m trying to destroy all nodes that match a query’s results.

This is what currently isn’t working.

    // Get all sessions with a given session id.
    const query = `
      query getSession($sid: string) {
        session as var(func: eq(sessionId, $sid)) {
    // Delete all of those sessions.
    const mutation = new Mutation();
    mutation.setDelNquads("uid(session) * * .");
    const request = new Request();

I’m sure I’m missing something simple, but I’ve not had any luck figuring it out.

As far I can tell, DQL Variables aren’t supported on Upsert Block. But feels like it is working on JS client. Need to test tho.

What is missing from your query is

const vars = {
        $id: "someID123",
const varsMap = req.getVarsMap();

Continue here dgraph-js/delete.spec.ts at 3f83745600818de64c968d9621a4cf7378bff147 · dgraph-io/dgraph-js · GitHub

1 Like

Should I be using dql variables in this case? I’m concerned that if the behavior is unintentional, it may be patched out later. I trust the source of the value so putting the value directly into the template would work just as well for me.

If it works for you, you can keep using DQL Vars. And now I know that it works on clients. Need to check if it works via RAW HTTP request. One thing I know is that DQL really doesn’t work on Ratel with custom value on the DQL Vars.

Nope, we won’t do that.

1 Like