Do I need to close client stub after every request?

Do I need to close client stub after every request?


0

I am using dgraph-js and have an app.ts file which holds all the services variables such like the client stub

export const dgraphStub = dgraph.clientStubFromCloudEndpoint(
    process.env.DGRAPH_URI!,
    process.env.DGRAPH_KEY!
);

export const dgraphClient = new dgraph.DgraphClient(dgraphStub);
dgraphClient.setDebugMode(true);

Now when I do something in dgraph like below

async function GetComment(commentId: string): Promise<IComment> {
    const txn = dgraphClient.newTxn({ readOnly: true });
    try {
        const comment = await txn.queryWithVars(GetCommentQuery, {
            $a: commentId,
        });
        return comment.getJson().findComment[0] as IComment;
    } catch (err) {
        console.error(err);
        return;
    } finally {
        await txn.discard();
    }
}

do I need to close the client stub or can I leave it because my app truly never finishes because it is a apollo graphql server thus, should I close the stub. I am new to transcations and dgraph and am not sure what to do as I do not want any random errors in production


Load 5 more related questions


Show fewer related questions

0



Leave a Reply

Your email address will not be published. Required fields are marked *