DQL @If Statement - Combine two statements

I have a lambda for GraphQL like so:

async function toggleVote({ args, graphql, dql, authHeader }: any) {

    const claimsBase64 = authHeader.value.split(".")[1];
    const claims = JSON.parse(atob(claimsBase64));
    const featureID = args.id;

    const q = `
    query {
        u(func: uid("${featureID}")) {
            uid
            Feature.votes @filter(eq(User.email, "${claims.email}")) {
                uid
                User.email
            }
        }
    }
    `;

    const r = await dql.query(q);
    const feature = r.data ? r.data.u[0]['Feature.votes'] : null;
    const type = feature ? 'delete' : 'set';

    const q2 = `
        upsert {
            query {
                u(func: eq(User.email, "${claims.email}")) {
                    User as uid
                }
            }
            mutation {
                ${type} {
                    <${featureID}> <Feature.votes> uid(User) .
                    uid(User) <User.votedFor> <${featureID}> .
                }
            }
        }
    `;

    const m = await dql.mutate(q2);
    return m.data ? type : null;
}

(self as any).addGraphQLResolvers({
    "Mutation.toggleVote": toggleVote,
});

Is it possible to use the @if directive in DQL to combine the two queries into one query?

I am trying this to no avail:

upsert {
    query {
        q1(func: eq(User.email, "[email protected]")) {
            User as uid
        }
        q2(func: uid("0xfffd8d6aac7af607")) {
            uid
            Feature.votes @filter(eq(User.email, "[email protected]")) {
                r as uid
                User.email
            }
        }
    }
    mutation @if(eq(len(r), 1)) {
        delete {
            <0xfffd8d6aac7af607> <Feature.votes> uid(User) .
            uid(User) <User.votedFor> <0xfffd8d6aac7af607> .
        }
    }
    mutation @if(eq(len(r), 0)) {
        set {
            <0xfffd8d6aac7af607> <Feature.votes> uid(User) .
            uid(User) <User.votedFor> <0xfffd8d6aac7af607> .
        }
    }
}

J

So it turns out it works fine.

The problem was running an upsert in DQL in Dgraph Cloud.

J