From ff8fa5071875e5bd8514257aaf47dcff12bff09f Mon Sep 17 00:00:00 2001 From: Rob Gilson Date: Wed, 8 Jul 2020 01:58:46 -0400 Subject: [PATCH] Add Serialize and Deserialize to ID This should allow types containing IDs to be serialized (eg. for saving to a database). --- src/scalars/id.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/scalars/id.rs b/src/scalars/id.rs index ca449b3a..3da422a9 100644 --- a/src/scalars/id.rs +++ b/src/scalars/id.rs @@ -2,6 +2,7 @@ use crate::{InputValueError, InputValueResult, ScalarType, Value}; use async_graphql_derive::Scalar; #[cfg(feature = "bson")] use bson::oid::{self, ObjectId}; +use serde::{Deserialize, Serialize}; use std::convert::TryFrom; use std::num::ParseIntError; use std::ops::{Deref, DerefMut}; @@ -9,7 +10,7 @@ use std::ops::{Deref, DerefMut}; /// ID scalar /// /// The input is a `&str`, `String`, `usize` or `uuid::UUID`, and the output is a string. -#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug)] +#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Serialize, Deserialize)] pub struct ID(String); impl Deref for ID {