@@ -14,10 +14,10 @@ pub type ResponseResult<T> = Result<T, anyhow::Error>;
1414
1515#[ derive( Debug , Clone ) ]
1616pub struct DeploymentDetails {
17- pub deployment : Option < DeploymentId > ,
18- pub status_url : Option < Url > ,
19- pub query_url : Url ,
20- pub query_auth_token : Option < String > ,
17+ deployment : Option < DeploymentId > ,
18+ status_url : Option < Url > ,
19+ query_url : Url ,
20+ query_auth_token : Option < String > ,
2121}
2222
2323impl DeploymentDetails {
@@ -79,6 +79,7 @@ struct DeploymentClient {
7979 pub http_client : reqwest:: Client ,
8080 pub status : Option < Receiver < DeploymentStatus > > ,
8181 pub query_url : Url ,
82+ pub query_auth_token : Option < String > ,
8283}
8384
8485impl DeploymentClient {
@@ -99,6 +100,7 @@ impl DeploymentClient {
99100 None => None ,
100101 } ,
101102 query_url : details. query_url ,
103+ query_auth_token : details. query_auth_token ,
102104 }
103105 }
104106
@@ -118,13 +120,17 @@ impl DeploymentClient {
118120 }
119121
120122 let body = T :: build_query ( variables) ;
121- let reqwest_response = self
123+ let mut req = self
122124 . http_client
123125 . post ( self . query_url . as_ref ( ) )
124126 . header ( header:: USER_AGENT , "indexer-common" )
125- . json ( & body)
126- . send ( )
127- . await ?;
127+ . json ( & body) ;
128+
129+ if let Some ( token) = self . query_auth_token . as_ref ( ) {
130+ req = req. header ( header:: AUTHORIZATION , format ! ( "Bearer {}" , token) ) ;
131+ }
132+
133+ let reqwest_response = req. send ( ) . await ?;
128134 let response: graphql_client:: Response < T :: ResponseData > = reqwest_response. json ( ) . await ?;
129135
130136 // TODO handle partial responses
@@ -154,14 +160,18 @@ impl DeploymentClient {
154160 }
155161 }
156162
157- Ok ( self
163+ let mut req = self
158164 . http_client
159165 . post ( self . query_url . as_ref ( ) )
160166 . header ( header:: USER_AGENT , "indexer-common" )
161167 . header ( header:: CONTENT_TYPE , "application/json" )
162- . body ( body)
163- . send ( )
164- . await ?)
168+ . body ( body) ;
169+
170+ if let Some ( token) = self . query_auth_token . as_ref ( ) {
171+ req = req. header ( header:: AUTHORIZATION , format ! ( "Bearer {}" , token) ) ;
172+ }
173+
174+ Ok ( req. send ( ) . await ?)
165175 }
166176}
167177
0 commit comments