Skip to content

Commit

Permalink
Encode bytes as hex strings in graphql type conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
sandreae committed Sep 7, 2023
1 parent 46b4293 commit b55ebcd
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions aquadoggo/src/graphql/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ pub fn gql_scalar(operation_value: &OperationValue) -> Value {
OperationValue::Float(value) => value.to_owned().into(),
OperationValue::Integer(value) => value.to_owned().into(),
OperationValue::String(value) => value.to_owned().into(),
OperationValue::Bytes(value) => value.to_owned().into(),
OperationValue::Bytes(value) => {
let hex_string = hex::encode(value);
hex_string.into()
}
_ => panic!("This method is not used for relation types"),
}
}
Expand Down Expand Up @@ -93,6 +96,11 @@ pub fn filter_to_operation_value(
FieldType::Integer => filter_value.i64()?.into(),
FieldType::Float => filter_value.f64()?.into(),
FieldType::String => filter_value.string()?.into(),
FieldType::Bytes => {
let hex_string = filter_value.string()?;
let bytes = hex::decode(hex_string)?;
bytes[..].into()
}
// We are only ever dealing with list items here
FieldType::Relation(_) | FieldType::RelationList(_) => {
DocumentId::new(&filter_value.string()?.parse()?).into()
Expand All @@ -101,11 +109,6 @@ pub fn filter_to_operation_value(
let document_view_id: DocumentViewId = filter_value.string()?.parse()?;
document_view_id.into()
}
FieldType::Bytes => {
let hex_string = filter_value.string()?;
let bytes = hex::decode(hex_string)?;
bytes[..].into()
}
};

Ok(value)
Expand Down

0 comments on commit b55ebcd

Please sign in to comment.