Add Serialize and Deserialize to ID

This should allow types containing IDs to be serialized (eg. for saving to a database).
This commit is contained in:
Rob Gilson 2020-07-08 01:58:46 -04:00 committed by GitHub
parent 788c1895fe
commit ff8fa50718

View File

@ -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 {