1+ import * as grpc from "grpc" ;
2+
13import * as messages from "../generated/api_pb" ;
24
35import { DgraphClient } from "./client" ;
@@ -41,8 +43,8 @@ export class Txn {
4143 * need to be made in the same transaction, it's convenient to chain the method,
4244 * e.g. client.newTxn().query("...").
4345 */
44- public query ( q : string ) : Promise < types . Response > {
45- return this . queryWithVars ( q ) ;
46+ public query ( q : string , options ?: grpc . CallOptions | null ) : Promise < types . Response > {
47+ return this . queryWithVars ( q , null , options ) ;
4648 }
4749
4850 /**
@@ -52,6 +54,7 @@ export class Txn {
5254 public async queryWithVars (
5355 q : string ,
5456 vars ?: { [ k : string ] : any } | null , // tslint:disable-line no-any
57+ options ?: grpc . CallOptions | null ,
5558 ) : Promise < types . Response > {
5659 if ( this . finished ) {
5760 this . dc . debug ( `Query request (ERR_FINISHED):\nquery = ${ q } \nvars = ${ vars } ` ) ;
@@ -74,7 +77,7 @@ export class Txn {
7477 this . dc . debug ( `Query request:\n${ stringifyMessage ( req ) } ` ) ;
7578
7679 const c = this . dc . anyClient ( ) ;
77- const res = types . createResponse ( await c . query ( req ) ) ;
80+ const res = types . createResponse ( await c . query ( req , options ) ) ;
7881 this . mergeContext ( res . getTxn ( ) ) ;
7982 this . dc . debug ( `Query response:\n${ stringifyMessage ( res ) } ` ) ;
8083
@@ -93,7 +96,7 @@ export class Txn {
9396 * If the mutation fails, then the transaction is discarded and all future
9497 * operations on it will fail.
9598 */
96- public async mutate ( mu : types . Mutation ) : Promise < messages . Assigned > {
99+ public async mutate ( mu : types . Mutation , options ?: grpc . CallOptions | null ) : Promise < messages . Assigned > {
97100 if ( this . finished ) {
98101 this . dc . debug ( `Mutate request (ERR_FINISHED):\nmutation = ${ stringifyMessage ( mu ) } ` ) ;
99102 throw ERR_FINISHED ;
@@ -106,7 +109,7 @@ export class Txn {
106109 let ag : messages . Assigned ;
107110 const c = this . dc . anyClient ( ) ;
108111 try {
109- ag = await c . mutate ( < messages . Mutation > mu ) ;
112+ ag = await c . mutate ( < messages . Mutation > mu , options ) ;
110113 } catch ( e ) {
111114 // Since a mutation error occurred, the txn should no longer be used (some
112115 // mutations could have applied but not others, but we don't know which ones).
@@ -142,7 +145,7 @@ export class Txn {
142145 * It's up to the user to decide if they wish to retry. In this case, the user
143146 * should create a new transaction.
144147 */
145- public async commit ( ) : Promise < void > {
148+ public async commit ( options ?: grpc . CallOptions | null ) : Promise < void > {
146149 if ( this . finished ) {
147150 throw ERR_FINISHED ;
148151 }
@@ -154,7 +157,7 @@ export class Txn {
154157
155158 const c = this . dc . anyClient ( ) ;
156159 try {
157- await c . commitOrAbort ( this . ctx ) ;
160+ await c . commitOrAbort ( this . ctx , options ) ;
158161 } catch ( e ) {
159162 throw isAbortedError ( e ) ? ERR_ABORTED : e ;
160163 }
@@ -170,7 +173,7 @@ export class Txn {
170173 * is unavailable. In these cases, the server will eventually do the transaction
171174 * clean up.
172175 */
173- public async discard ( ) : Promise < void > {
176+ public async discard ( options ?: grpc . CallOptions | null ) : Promise < void > {
174177 if ( this . finished ) {
175178 return ;
176179 }
@@ -182,7 +185,7 @@ export class Txn {
182185
183186 this . ctx . setAborted ( true ) ;
184187 const c = this . dc . anyClient ( ) ;
185- await c . commitOrAbort ( this . ctx ) ;
188+ await c . commitOrAbort ( this . ctx , options ) ;
186189 }
187190
188191 private mergeContext ( src ?: messages . TxnContext | null ) : void {
0 commit comments