Rename ToInputValue::to to to_input_value()
This commit is contained in:
parent
164aa29fdc
commit
0372de84d5
13 changed files with 28 additions and 28 deletions
|
@ -160,7 +160,7 @@ pub trait FromInputValue: Sized {
|
|||
/// Losslessly clones a Rust data type into an InputValue.
|
||||
pub trait ToInputValue: Sized {
|
||||
/// Performs the conversion.
|
||||
fn to(&self) -> InputValue;
|
||||
fn to_input_value(&self) -> InputValue;
|
||||
}
|
||||
|
||||
impl<'a> Type<'a> {
|
||||
|
|
|
@ -485,7 +485,7 @@ impl<'r> Registry<'r> {
|
|||
where
|
||||
T: GraphQLType + ToInputValue + FromInputValue,
|
||||
{
|
||||
Argument::new(name, self.get_type::<Option<T>>(info)).default_value(value.to())
|
||||
Argument::new(name, self.get_type::<Option<T>>(info)).default_value(value.to_input_value())
|
||||
}
|
||||
|
||||
fn insert_placeholder(&mut self, name: Name, of_type: Type<'r>) {
|
||||
|
|
|
@ -105,7 +105,7 @@ macro_rules! graphql_enum {
|
|||
}
|
||||
|
||||
impl $crate::ToInputValue for $name {
|
||||
fn to(&self) -> $crate::InputValue {
|
||||
fn to_input_value(&self) -> $crate::InputValue {
|
||||
match *self {
|
||||
$(
|
||||
graphql_enum!(@as_pattern, $eval) =>
|
||||
|
|
|
@ -84,7 +84,7 @@ macro_rules! graphql_input_object {
|
|||
) => {
|
||||
$crate::InputValue::object(vec![
|
||||
$(
|
||||
($crate::to_camel_case(stringify!($field_name)), $selfvar.$field_name.to())
|
||||
($crate::to_camel_case(stringify!($field_name)), $selfvar.$field_name.to_input_value())
|
||||
),*
|
||||
].into_iter().collect())
|
||||
};
|
||||
|
@ -232,7 +232,7 @@ macro_rules! graphql_input_object {
|
|||
}
|
||||
|
||||
impl $crate::ToInputValue for $name {
|
||||
fn to(&self) -> $crate::InputValue {
|
||||
fn to_input_value(&self) -> $crate::InputValue {
|
||||
graphql_input_object!(@generate_to_input_value, $name, self, $fields)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ macro_rules! graphql_scalar {
|
|||
// string or none).
|
||||
//
|
||||
// ( $resolve_selfvar, $resolve_body ): the "self" argument and body for the
|
||||
// resolve() method on GraphQLType and the to() method on ToInputValue.
|
||||
// resolve() method on GraphQLType and the to_input_value() method on ToInputValue.
|
||||
//
|
||||
// ( $fiv_arg, $fiv_result, $fiv_body ): the method argument, result type,
|
||||
// and body for the from() method on FromInputValue.
|
||||
|
@ -88,8 +88,8 @@ macro_rules! graphql_scalar {
|
|||
}
|
||||
|
||||
impl $crate::ToInputValue for $name {
|
||||
fn to(&$resolve_selfvar) -> $crate::InputValue {
|
||||
$crate::ToInputValue::to(&$resolve_body)
|
||||
fn to_input_value(&$resolve_selfvar) -> $crate::InputValue {
|
||||
$crate::ToInputValue::to_input_value(&$resolve_body)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -52,9 +52,9 @@ impl<T> ToInputValue for Option<T>
|
|||
where
|
||||
T: ToInputValue,
|
||||
{
|
||||
fn to(&self) -> InputValue {
|
||||
fn to_input_value(&self) -> InputValue {
|
||||
match *self {
|
||||
Some(ref v) => v.to(),
|
||||
Some(ref v) => v.to_input_value(),
|
||||
None => InputValue::null(),
|
||||
}
|
||||
}
|
||||
|
@ -117,8 +117,8 @@ impl<T> ToInputValue for Vec<T>
|
|||
where
|
||||
T: ToInputValue,
|
||||
{
|
||||
fn to(&self) -> InputValue {
|
||||
InputValue::list(self.iter().map(|v| v.to()).collect())
|
||||
fn to_input_value(&self) -> InputValue {
|
||||
InputValue::list(self.iter().map(|v| v.to_input_value()).collect())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -155,7 +155,7 @@ impl<'a, T> ToInputValue for &'a [T]
|
|||
where
|
||||
T: ToInputValue,
|
||||
{
|
||||
fn to(&self) -> InputValue {
|
||||
InputValue::list(self.iter().map(|v| v.to()).collect())
|
||||
fn to_input_value(&self) -> InputValue {
|
||||
InputValue::list(self.iter().map(|v| v.to_input_value()).collect())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,8 +66,8 @@ impl<T> ToInputValue for Box<T>
|
|||
where
|
||||
T: ToInputValue,
|
||||
{
|
||||
fn to(&self) -> InputValue {
|
||||
(**self).to()
|
||||
fn to_input_value(&self) -> InputValue {
|
||||
(**self).to_input_value()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -120,7 +120,7 @@ impl<'a, T> ToInputValue for &'a T
|
|||
where
|
||||
T: ToInputValue,
|
||||
{
|
||||
fn to(&self) -> InputValue {
|
||||
(**self).to()
|
||||
fn to_input_value(&self) -> InputValue {
|
||||
(**self).to_input_value()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ impl<'a> GraphQLType for &'a str {
|
|||
}
|
||||
|
||||
impl<'a> ToInputValue for &'a str {
|
||||
fn to(&self) -> InputValue {
|
||||
fn to_input_value(&self) -> InputValue {
|
||||
InputValue::string(self)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -110,7 +110,7 @@ impl Value {
|
|||
}
|
||||
|
||||
impl ToInputValue for Value {
|
||||
fn to(&self) -> InputValue {
|
||||
fn to_input_value(&self) -> InputValue {
|
||||
match *self {
|
||||
Value::Null => InputValue::Null,
|
||||
Value::Int(i) => InputValue::Int(i),
|
||||
|
@ -118,12 +118,12 @@ impl ToInputValue for Value {
|
|||
Value::String(ref s) => InputValue::String(s.clone()),
|
||||
Value::Boolean(b) => InputValue::Boolean(b),
|
||||
Value::List(ref l) => {
|
||||
InputValue::List(l.iter().map(|x| Spanning::unlocated(x.to())).collect())
|
||||
InputValue::List(l.iter().map(|x| Spanning::unlocated(x.to_input_value())).collect())
|
||||
}
|
||||
Value::Object(ref o) => InputValue::Object(
|
||||
o.iter()
|
||||
.map(|(k, v)| {
|
||||
(Spanning::unlocated(k.clone()), Spanning::unlocated(v.to()))
|
||||
(Spanning::unlocated(k.clone()), Spanning::unlocated(v.to_input_value()))
|
||||
})
|
||||
.collect(),
|
||||
),
|
||||
|
|
|
@ -181,7 +181,7 @@ pub fn impl_enum(ast: &syn::DeriveInput) -> Tokens {
|
|||
}
|
||||
|
||||
impl ::juniper::ToInputValue for #ident {
|
||||
fn to(&self) -> ::juniper::InputValue {
|
||||
fn to_input_value(&self) -> ::juniper::InputValue {
|
||||
match self {
|
||||
#(#to_inputs)*
|
||||
}
|
||||
|
|
|
@ -178,7 +178,7 @@ pub fn impl_input_object(ast: &syn::DeriveInput) -> Tokens {
|
|||
|
||||
// Build to_input clause.
|
||||
let to_input = quote!{
|
||||
(#name, self.#field_ident.to()),
|
||||
(#name, self.#field_ident.to_input_value()),
|
||||
};
|
||||
to_inputs.push(to_input);
|
||||
}
|
||||
|
@ -217,7 +217,7 @@ pub fn impl_input_object(ast: &syn::DeriveInput) -> Tokens {
|
|||
}
|
||||
|
||||
impl ::juniper::ToInputValue for #ident {
|
||||
fn to(&self) -> ::juniper::InputValue {
|
||||
fn to_input_value(&self) -> ::juniper::InputValue {
|
||||
::juniper::InputValue::object(vec![
|
||||
#(#to_inputs)*
|
||||
].into_iter().collect())
|
||||
|
|
|
@ -26,14 +26,14 @@ fn test_derived_enum() {
|
|||
assert_eq!(meta.description(), Some(&"enum descr".to_string()));
|
||||
|
||||
// Test Regular variant.
|
||||
assert_eq!(SomeEnum::Regular.to(), InputValue::String("REGULAR".into()));
|
||||
assert_eq!(SomeEnum::Regular.to_input_value(), InputValue::String("REGULAR".into()));
|
||||
assert_eq!(
|
||||
FromInputValue::from_input_value(&InputValue::String("REGULAR".into())),
|
||||
Some(SomeEnum::Regular)
|
||||
);
|
||||
|
||||
// Test FULL variant.
|
||||
assert_eq!(SomeEnum::Full.to(), InputValue::String("FULL".into()));
|
||||
assert_eq!(SomeEnum::Full.to_input_value(), InputValue::String("FULL".into()));
|
||||
assert_eq!(
|
||||
FromInputValue::from_input_value(&InputValue::String("FULL".into())),
|
||||
Some(SomeEnum::Full)
|
||||
|
|
|
@ -26,6 +26,6 @@ fn test_derived_input_object() {
|
|||
regular_field: "a".to_string(),
|
||||
c: 33,
|
||||
};
|
||||
let restored: Input = FromInputValue::from_input_value(&obj.to()).unwrap();
|
||||
let restored: Input = FromInputValue::from_input_value(&obj.to_input_value()).unwrap();
|
||||
assert_eq!(obj, restored);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue