@@ -2203,24 +2203,50 @@ impl GithubClient {
2203
2203
}
2204
2204
2205
2205
/// Issues an ad-hoc GraphQL query.
2206
- pub async fn graphql_query < T : serde:: de:: DeserializeOwned > (
2206
+ ///
2207
+ /// You are responsible for checking the `errors` array when calling this
2208
+ /// function to determine if there is an error. Only use this if you are
2209
+ /// looking for specific error codes, or don't care about errors. Use
2210
+ /// [`GithubClient::graphql_query`] if you would prefer to have a generic
2211
+ /// error message.
2212
+ pub async fn graphql_query_with_errors (
2207
2213
& self ,
2208
2214
query : & str ,
2209
2215
vars : serde_json:: Value ,
2210
- ) -> anyhow:: Result < T > {
2216
+ ) -> anyhow:: Result < serde_json :: Value > {
2211
2217
self . json ( self . post ( & self . graphql_url ) . json ( & serde_json:: json!( {
2212
2218
"query" : query,
2213
2219
"variables" : vars,
2214
2220
} ) ) )
2215
2221
. await
2216
2222
}
2217
2223
2224
+ /// Issues an ad-hoc GraphQL query.
2225
+ ///
2226
+ /// See [`GithubClient::graphql_query_with_errors`] if you need to check
2227
+ /// for specific errors.
2228
+ pub async fn graphql_query (
2229
+ & self ,
2230
+ query : & str ,
2231
+ vars : serde_json:: Value ,
2232
+ ) -> anyhow:: Result < serde_json:: Value > {
2233
+ let result: serde_json:: Value = self . graphql_query_with_errors ( query, vars) . await ?;
2234
+ if let Some ( errors) = result[ "errors" ] . as_array ( ) {
2235
+ let messages: Vec < _ > = errors
2236
+ . iter ( )
2237
+ . map ( |err| err[ "message" ] . as_str ( ) . unwrap_or_default ( ) )
2238
+ . collect ( ) ;
2239
+ anyhow:: bail!( "error: {}" , messages. join( "\n " ) ) ;
2240
+ }
2241
+ Ok ( result)
2242
+ }
2243
+
2218
2244
/// Returns the object ID of the given user.
2219
2245
///
2220
2246
/// Returns `None` if the user doesn't exist.
2221
2247
pub async fn user_object_id ( & self , user : & str ) -> anyhow:: Result < Option < String > > {
2222
2248
let user_info: serde_json:: Value = self
2223
- . graphql_query (
2249
+ . graphql_query_with_errors (
2224
2250
"query($user:String!) {
2225
2251
user(login:$user) {
2226
2252
id
@@ -2273,7 +2299,7 @@ impl GithubClient {
2273
2299
// work on forks. This GraphQL query seems to work fairly reliably,
2274
2300
// and seems to cost only 1 point.
2275
2301
match self
2276
- . graphql_query :: < serde_json :: Value > (
2302
+ . graphql_query_with_errors (
2277
2303
"query($repository_owner:String!, $repository_name:String!, $user_id:ID!) {
2278
2304
repository(owner: $repository_owner, name: $repository_name) {
2279
2305
defaultBranchRef {
0 commit comments