Skip to content

Commit 8db8527

Browse files
committed
Testing making TableData fault tolerant
If the data for a single run could not be found, it should not prevent the data for other runs being returned. The way async-graphql handles this is... odd. By making the resolver return an Option<Result<T,E>> but only ever actually returning a Some(_) variant, errors are added to the errors list in the response and the rest of the query is executed as expected. Adding the extra Option layer breaks error handling via the ? operator which would make the resolver noisy so the inner logic is moved into a non-object impl block which can then be called and wrapped by the graphql macro wrapped version of the same method.
1 parent 560b026 commit 8db8527

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/model.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,16 @@ impl TableData {
135135
&self,
136136
ctx: &Context<'_>,
137137
columns: Option<Vec<String>>,
138+
) -> Option<Result<HashMap<String, Vec<Value>>>> {
139+
Some(self.inner_data(ctx, columns).await)
140+
}
141+
}
142+
143+
impl TableData {
144+
async fn inner_data(
145+
&self,
146+
ctx: &Context<'_>,
147+
columns: Option<Vec<String>>,
138148
) -> Result<HashMap<String, Vec<Value>>> {
139149
let auth = ctx.data::<Option<AuthHeader>>()?;
140150
let headers = auth.as_ref().map(AuthHeader::as_header_map);

0 commit comments

Comments
 (0)