The answer is this
async function IncrementOrDecrementHashtagPins(
hashtag: string,
increment: boolean
): Promise<boolean> {
// Hashtag.pinnedByCount: int .
const txn = dgraphClient.newTxn({});
try {
const uid = await GetHashtagUid(hashtag);
if (!uid) return false;
const mutation = new dgraph.Mutation();
if (increment) {
mutation.setSetNquads(
`<${uid}> <Hashtag.pinnedByCount> "1"^^<xs:int> .`
);
} else {
mutation.setSetNquads(
`<${uid}> <Hashtag.pinnedByCount> "-1"^^<xs:int> .`
);
}
await txn.mutate(mutation);
await txn.commit();
return true;
} catch (err) {
return false;
} finally {
await txn.discard();
}
}