Change the signature of the `connection::query` function to allow the callback to use any type that implements `Into<Error>`. #671
This commit is contained in:
parent
6272d72a15
commit
789cf57d32
|
@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
|
|||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## Unreleased
|
||||
|
||||
- Change the signature of the `connection::query` function to allow the callback to use any type that implements `Into<Error>`.
|
||||
|
||||
## [2.11.3] 2021-11-13
|
||||
|
||||
- Implemented CursorType for i32/i64. [#701](https://github.com/async-graphql/async-graphql/pull/701)
|
||||
|
|
|
@ -8,12 +8,13 @@ mod page_info;
|
|||
use std::fmt::Display;
|
||||
use std::future::Future;
|
||||
|
||||
use crate::{Result, SimpleObject};
|
||||
pub use connection_type::Connection;
|
||||
pub use cursor::CursorType;
|
||||
pub use edge::Edge;
|
||||
pub use page_info::PageInfo;
|
||||
|
||||
use crate::{Error, Result, SimpleObject};
|
||||
|
||||
/// Empty additional fields
|
||||
#[derive(SimpleObject)]
|
||||
#[graphql(internal, dummy)]
|
||||
|
@ -62,7 +63,7 @@ pub struct EmptyFields;
|
|||
/// (start..end).into_iter().map(|n|
|
||||
/// Edge::with_additional_fields(n, n as i32, Diff{ diff: (10000 - n) as i32 })),
|
||||
/// );
|
||||
/// Ok(connection)
|
||||
/// Ok::<_, Error>(connection)
|
||||
/// }).await
|
||||
/// }
|
||||
/// }
|
||||
|
@ -89,7 +90,7 @@ pub struct EmptyFields;
|
|||
/// }));
|
||||
/// });
|
||||
/// ```
|
||||
pub async fn query<Cursor, Node, ConnectionFields, EdgeFields, F, R>(
|
||||
pub async fn query<Cursor, Node, ConnectionFields, EdgeFields, F, R, E>(
|
||||
after: Option<String>,
|
||||
before: Option<String>,
|
||||
first: Option<i32>,
|
||||
|
@ -100,7 +101,8 @@ where
|
|||
Cursor: CursorType + Send + Sync,
|
||||
<Cursor as CursorType>::Error: Display + Send + Sync + 'static,
|
||||
F: FnOnce(Option<Cursor>, Option<Cursor>, Option<usize>, Option<usize>) -> R,
|
||||
R: Future<Output = Result<Connection<Cursor, Node, ConnectionFields, EdgeFields>>>,
|
||||
R: Future<Output = Result<Connection<Cursor, Node, ConnectionFields, EdgeFields>, E>>,
|
||||
E: Into<Error>,
|
||||
{
|
||||
if first.is_some() && last.is_some() {
|
||||
return Err("The \"first\" and \"last\" parameters cannot exist at the same time".into());
|
||||
|
@ -132,5 +134,5 @@ where
|
|||
None => None,
|
||||
};
|
||||
|
||||
f(after, before, first, last).await
|
||||
f(after, before, first, last).await.map_err(Into::into)
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ pub async fn test_connection_additional_fields() {
|
|||
},
|
||||
)
|
||||
}));
|
||||
Ok(connection)
|
||||
Ok::<_, Error>(connection)
|
||||
},
|
||||
)
|
||||
.await
|
||||
|
|
Loading…
Reference in New Issue