|
2 | 2 | #![cfg_attr(not(any(doc, test)), doc = env!("CARGO_PKG_NAME"))]
|
3 | 3 | #![cfg_attr(test, expect(unused_crate_dependencies, reason = "examples"))]
|
4 | 4 |
|
5 |
| -use std::{error::Error, fmt, string::FromUtf8Error, sync::Arc}; |
| 5 | +use std::{error::Error, string::FromUtf8Error, sync::Arc}; |
6 | 6 |
|
7 |
| -use derive_more::with_trait::Display; |
| 7 | +use derive_more::with_trait::{Debug, Display}; |
8 | 8 | use http_body_util::BodyExt as _;
|
9 | 9 | use hyper::{
|
10 | 10 | Method, Request, Response, StatusCode,
|
|
34 | 34 | SubscriptionT::TypeInfo: Sync,
|
35 | 35 | CtxT: Sync,
|
36 | 36 | S: ScalarValue + Send + Sync,
|
37 |
| - B: Body<Error: fmt::Display>, |
| 37 | + B: Body<Error: Display>, |
38 | 38 | {
|
39 | 39 | match parse_req(req).await {
|
40 | 40 | Ok(req) => execute_request_sync(schema, context, req).await,
|
|
58 | 58 | SubscriptionT::TypeInfo: Sync,
|
59 | 59 | CtxT: Sync,
|
60 | 60 | S: ScalarValue + Send + Sync,
|
61 |
| - B: Body<Error: fmt::Display>, |
| 61 | + B: Body<Error: Display>, |
62 | 62 | {
|
63 | 63 | match parse_req(req).await {
|
64 | 64 | Ok(req) => execute_request(schema, context, req).await,
|
|
69 | 69 | async fn parse_req<S, B>(req: Request<B>) -> Result<GraphQLBatchRequest<S>, Response<String>>
|
70 | 70 | where
|
71 | 71 | S: ScalarValue,
|
72 |
| - B: Body<Error: fmt::Display>, |
| 72 | + B: Body<Error: Display>, |
73 | 73 | {
|
74 | 74 | match *req.method() {
|
75 | 75 | Method::GET => parse_get_req(req),
|
@@ -176,7 +176,7 @@ pub async fn playground(
|
176 | 176 |
|
177 | 177 | fn render_error<B>(err: GraphQLRequestError<B>) -> Response<String>
|
178 | 178 | where
|
179 |
| - B: Body<Error: fmt::Display>, |
| 179 | + B: Body<Error: Display>, |
180 | 180 | {
|
181 | 181 | let mut resp = new_response(StatusCode::BAD_REQUEST);
|
182 | 182 | *resp.body_mut() = err.to_string();
|
@@ -312,32 +312,21 @@ fn new_html_response(code: StatusCode) -> Response<String> {
|
312 | 312 | resp
|
313 | 313 | }
|
314 | 314 |
|
315 |
| -#[derive(Display)] |
| 315 | +// TODO: Use `#[debug(forward)]` once `derive_more::Debug` is capable of it. |
| 316 | +#[derive(Debug, Display)] |
316 | 317 | enum GraphQLRequestError<B: Body> {
|
| 318 | + #[debug("{_0:?}")] |
317 | 319 | BodyHyper(B::Error),
|
| 320 | + #[debug("{_0:?}")] |
318 | 321 | BodyUtf8(FromUtf8Error),
|
| 322 | + #[debug("{_0:?}")] |
319 | 323 | BodyJSONError(SerdeError),
|
| 324 | + #[debug("{_0:?}")] |
320 | 325 | Variables(SerdeError),
|
| 326 | + #[debug("{_0:?}")] |
321 | 327 | Invalid(String),
|
322 | 328 | }
|
323 | 329 |
|
324 |
| -// NOTE: Manual implementation instead of `#[derive(Debug)]` is used to omit imposing unnecessary |
325 |
| -// `B: Debug` bound on the implementation. |
326 |
| -impl<B> fmt::Debug for GraphQLRequestError<B> |
327 |
| -where |
328 |
| - B: Body<Error: fmt::Debug>, |
329 |
| -{ |
330 |
| - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
331 |
| - match self { |
332 |
| - Self::BodyHyper(e) => fmt::Debug::fmt(e, f), |
333 |
| - Self::BodyUtf8(e) => fmt::Debug::fmt(e, f), |
334 |
| - Self::BodyJSONError(e) => fmt::Debug::fmt(e, f), |
335 |
| - Self::Variables(e) => fmt::Debug::fmt(e, f), |
336 |
| - Self::Invalid(e) => fmt::Debug::fmt(e, f), |
337 |
| - } |
338 |
| - } |
339 |
| -} |
340 |
| - |
341 | 330 | impl<B> Error for GraphQLRequestError<B>
|
342 | 331 | where
|
343 | 332 | B: Body<Error: Error + 'static>,
|
|
0 commit comments