Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhoule committed Aug 31, 2023
1 parent 430cd7b commit d25792d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct SimpleGqlBatchResponse {
errors: Vec<GQLError>,
}

#[derive(Debug, Deserialize)]
#[derive(Debug, Serialize, Deserialize)]
#[serde(untagged)]
enum Response {
Single(SimpleGqlResponse),
Expand Down Expand Up @@ -91,8 +91,12 @@ impl QueryResult {

pub fn errors(&self) -> Vec<&GQLError> {
match self.response {
PrismaResponse::Single(ref s) => s.errors().collect(),
PrismaResponse::Multi(ref m) => m.errors().collect(),
Response::Single(ref s) => s.errors.iter().collect(),
Response::Multi(ref m) => m
.errors
.iter()
.chain(m.batch_result.iter().flat_map(|res| res.errors.iter()))
.collect(),
}
}

Expand Down Expand Up @@ -121,15 +125,17 @@ impl From<PrismaResponse> for QueryResult {
}),
},
PrismaResponse::Multi(reses) => QueryResult {
response: Response::Multi(
reses
response: Response::Multi(SimpleGqlBatchResponse {
batch_result: reses
.batch_result
.into_iter()
.map(|res| SimpleGqlResponse {
data: serde_json::to_value(&response.data).unwrap(),
errors: res.errors,
})
.collect(),
),
errors: reses.errors,
}),
},
}
}
Expand Down
4 changes: 2 additions & 2 deletions query-engine/request-handlers/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ pub struct GQLResponse {
#[serde(rename_all = "camelCase")]
pub struct GQLBatchResponse {
#[serde(skip_serializing_if = "Vec::is_empty")]
batch_result: Vec<GQLResponse>,
pub batch_result: Vec<GQLResponse>,

#[serde(skip_serializing_if = "Vec::is_empty")]
errors: Vec<GQLError>,
pub errors: Vec<GQLError>,

#[serde(skip_serializing_if = "IndexMap::is_empty")]
extensions: Map,
Expand Down

0 comments on commit d25792d

Please sign in to comment.