Skip to content

Commit

Permalink
Fix bug introduced here after removing Option for deserialization
Browse files Browse the repository at this point in the history
  • Loading branch information
cecton committed Dec 4, 2021
1 parent 14e49f0 commit 6a6602e
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion apollo-router-core/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ pub struct Request {
pub operation_name: Option<String>,

/// The optional variables in the form of a json object.
#[serde(skip_serializing_if = "Object::is_empty", default)]
#[serde(
skip_serializing_if = "Object::is_empty",
default,
deserialize_with = "deserialize_null_default"
)]
#[builder(default)]
pub variables: Arc<Object>,

Expand All @@ -30,6 +34,16 @@ pub struct Request {
pub extensions: Object,
}

// NOTE: this deserialize helper is used to transform `null` to Default::default()
fn deserialize_null_default<'de, D, T: Default + Deserialize<'de>>(
deserializer: D,
) -> Result<T, D::Error>
where
D: serde::Deserializer<'de>,
{
<Option<T>>::deserialize(deserializer).map(|x| x.unwrap_or_default())
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down

0 comments on commit 6a6602e

Please sign in to comment.