Skip to content

Upsert query variables fails #4286

@Q-Minh

Description

@Q-Minh

Working Upsert

const query = `
    query {
        user as q(func: eq(user.id, "${request.userId}"))
    }
    `;

const mu = new dgraph.Mutation();
mu.setDelNquads(`uid(user) * * .`);

const req = new dgraph.Request();
req.setQuery(query);
req.setMutationsList([mu]);
req.setCommitNow(true);

const res = await dgraphClient.newTxn().doRequest(req);

When directly inserting the value of request.userId into the query string via string interpolation, the node returned by the query is successfully deleted.

Failing upsert

const query = `
            query q($userId: string) {
                user as q(func: eq(user.id, $userId))
            }
        `;
    
const mu = new dgraph.Mutation();
mu.setDelNquads(`uid(user) * * .`);
    
const req = new dgraph.Request();
const vars = req.getVarsMap();
vars.set("$userId", `${request.userId}`);
req.setQuery(query);
req.setMutationsList([mu]);
req.setCommitNow(true);
    
const res = await dgraphClient.newTxn().doRequest(req);

When trying to use query variables and setting the corresponding entry in the variables map for $userId with `${request.userId}`, the node that should be returned by the query is not successfully deleted.

Is this an unsupported feature for upserts or is something wrong with the code?

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/querylang/varsIssues related to queries with GraphQL variablesarea/upsertIssues related to upsert operations.kind/bugSomething is broken.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions