Rename FromInputValue::from() to from_input_value()
This commit is contained in:
parent
0915c05c6c
commit
164aa29fdc
15 changed files with 27 additions and 27 deletions
juniper/src
juniper_codegen/src
juniper_tests/src/codegen
|
@ -154,7 +154,7 @@ pub type Document<'a> = Vec<Definition<'a>>;
|
||||||
/// enums or scalars.
|
/// enums or scalars.
|
||||||
pub trait FromInputValue: Sized {
|
pub trait FromInputValue: Sized {
|
||||||
/// Performs the conversion.
|
/// Performs the conversion.
|
||||||
fn from(v: &InputValue) -> Option<Self>;
|
fn from_input_value(v: &InputValue) -> Option<Self>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Losslessly clones a Rust data type into an InputValue.
|
/// Losslessly clones a Rust data type into an InputValue.
|
||||||
|
@ -302,7 +302,7 @@ impl InputValue {
|
||||||
where
|
where
|
||||||
T: FromInputValue,
|
T: FromInputValue,
|
||||||
{
|
{
|
||||||
<T as FromInputValue>::from(self)
|
<T as FromInputValue>::from_input_value(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Does the value represent null?
|
/// Does the value represent null?
|
||||||
|
|
|
@ -24,7 +24,7 @@ mod test {
|
||||||
let raw = "123e4567-e89b-12d3-a456-426655440000";
|
let raw = "123e4567-e89b-12d3-a456-426655440000";
|
||||||
let input = ::InputValue::String(raw.to_string());
|
let input = ::InputValue::String(raw.to_string());
|
||||||
|
|
||||||
let parsed: Uuid = ::FromInputValue::from(&input).unwrap();
|
let parsed: Uuid = ::FromInputValue::from_input_value(&input).unwrap();
|
||||||
let id = Uuid::parse_str(raw).unwrap();
|
let id = Uuid::parse_str(raw).unwrap();
|
||||||
|
|
||||||
assert_eq!(parsed, id);
|
assert_eq!(parsed, id);
|
||||||
|
|
|
@ -94,7 +94,7 @@ macro_rules! graphql_enum {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl $crate::FromInputValue for $name {
|
impl $crate::FromInputValue for $name {
|
||||||
fn from(v: &$crate::InputValue) -> Option<$name> {
|
fn from_input_value(v: &$crate::InputValue) -> Option<$name> {
|
||||||
match v.as_enum_value().or_else(|| v.as_string_value()) {
|
match v.as_enum_value().or_else(|| v.as_string_value()) {
|
||||||
$(
|
$(
|
||||||
Some(graphql_enum!(@as_pattern, $ename))
|
Some(graphql_enum!(@as_pattern, $ename))
|
||||||
|
|
|
@ -69,8 +69,8 @@ macro_rules! graphql_input_object {
|
||||||
|
|
||||||
match v {
|
match v {
|
||||||
$( Some(&&$crate::InputValue::Null) | None if true => $default, )*
|
$( Some(&&$crate::InputValue::Null) | None if true => $default, )*
|
||||||
Some(v) => $crate::FromInputValue::from(v).unwrap(),
|
Some(v) => $crate::FromInputValue::from_input_value(v).unwrap(),
|
||||||
_ => $crate::FromInputValue::from(&$crate::InputValue::null()).unwrap()
|
_ => $crate::FromInputValue::from_input_value(&$crate::InputValue::null()).unwrap()
|
||||||
}
|
}
|
||||||
} ),*
|
} ),*
|
||||||
})
|
})
|
||||||
|
@ -221,7 +221,7 @@ macro_rules! graphql_input_object {
|
||||||
graphql_input_object!(@generate_struct_fields, $meta, $pubmod, $name, $fields);
|
graphql_input_object!(@generate_struct_fields, $meta, $pubmod, $name, $fields);
|
||||||
|
|
||||||
impl $crate::FromInputValue for $name {
|
impl $crate::FromInputValue for $name {
|
||||||
fn from(value: &$crate::InputValue) -> Option<$name> {
|
fn from_input_value(value: &$crate::InputValue) -> Option<$name> {
|
||||||
if let Some(obj) = value.to_object_value() {
|
if let Some(obj) = value.to_object_value() {
|
||||||
graphql_input_object!(@generate_from_input_value, $name, obj, $fields)
|
graphql_input_object!(@generate_from_input_value, $name, obj, $fields)
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,7 +94,7 @@ macro_rules! graphql_scalar {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl $crate::FromInputValue for $name {
|
impl $crate::FromInputValue for $name {
|
||||||
fn from($fiv_arg: &$crate::InputValue) -> $fiv_result {
|
fn from_input_value($fiv_arg: &$crate::InputValue) -> $fiv_result {
|
||||||
$fiv_body
|
$fiv_body
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -194,7 +194,7 @@ fn default_name_input_value() {
|
||||||
.collect(),
|
.collect(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let dv: Option<DefaultName> = FromInputValue::from(&iv);
|
let dv: Option<DefaultName> = FromInputValue::from_input_value(&iv);
|
||||||
|
|
||||||
assert!(dv.is_some());
|
assert!(dv.is_some());
|
||||||
|
|
||||||
|
|
|
@ -345,7 +345,7 @@ impl<'a> ScalarMeta<'a> {
|
||||||
ScalarMeta {
|
ScalarMeta {
|
||||||
name: name,
|
name: name,
|
||||||
description: None,
|
description: None,
|
||||||
try_parse_fn: Box::new(|v: &InputValue| <T as FromInputValue>::from(v).is_some()),
|
try_parse_fn: Box::new(|v: &InputValue| <T as FromInputValue>::from_input_value(v).is_some()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -431,7 +431,7 @@ impl<'a> EnumMeta<'a> {
|
||||||
name: name,
|
name: name,
|
||||||
description: None,
|
description: None,
|
||||||
values: values.to_vec(),
|
values: values.to_vec(),
|
||||||
try_parse_fn: Box::new(|v: &InputValue| <T as FromInputValue>::from(v).is_some()),
|
try_parse_fn: Box::new(|v: &InputValue| <T as FromInputValue>::from_input_value(v).is_some()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -510,7 +510,7 @@ impl<'a> InputObjectMeta<'a> {
|
||||||
name: name,
|
name: name,
|
||||||
description: None,
|
description: None,
|
||||||
input_fields: input_fields.to_vec(),
|
input_fields: input_fields.to_vec(),
|
||||||
try_parse_fn: Box::new(|v: &InputValue| <T as FromInputValue>::from(v).is_some()),
|
try_parse_fn: Box::new(|v: &InputValue| <T as FromInputValue>::from_input_value(v).is_some()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ impl<T> FromInputValue for Option<T>
|
||||||
where
|
where
|
||||||
T: FromInputValue,
|
T: FromInputValue,
|
||||||
{
|
{
|
||||||
fn from(v: &InputValue) -> Option<Option<T>> {
|
fn from_input_value(v: &InputValue) -> Option<Option<T>> {
|
||||||
match v {
|
match v {
|
||||||
&InputValue::Null => Some(None),
|
&InputValue::Null => Some(None),
|
||||||
v => match v.convert() {
|
v => match v.convert() {
|
||||||
|
@ -93,7 +93,7 @@ impl<T> FromInputValue for Vec<T>
|
||||||
where
|
where
|
||||||
T: FromInputValue,
|
T: FromInputValue,
|
||||||
{
|
{
|
||||||
fn from(v: &InputValue) -> Option<Vec<T>> {
|
fn from_input_value(v: &InputValue) -> Option<Vec<T>> {
|
||||||
match *v {
|
match *v {
|
||||||
InputValue::List(ref ls) => {
|
InputValue::List(ref ls) => {
|
||||||
let v: Vec<_> = ls.iter().filter_map(|i| i.item.convert()).collect();
|
let v: Vec<_> = ls.iter().filter_map(|i| i.item.convert()).collect();
|
||||||
|
|
|
@ -54,8 +54,8 @@ impl<T> FromInputValue for Box<T>
|
||||||
where
|
where
|
||||||
T: FromInputValue,
|
T: FromInputValue,
|
||||||
{
|
{
|
||||||
fn from(v: &InputValue) -> Option<Box<T>> {
|
fn from_input_value(v: &InputValue) -> Option<Box<T>> {
|
||||||
match <T as FromInputValue>::from(v) {
|
match <T as FromInputValue>::from_input_value(v) {
|
||||||
Some(v) => Some(Box::new(v)),
|
Some(v) => Some(Box::new(v)),
|
||||||
None => None,
|
None => None,
|
||||||
}
|
}
|
||||||
|
|
|
@ -141,7 +141,7 @@ impl GraphQLType for () {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromInputValue for () {
|
impl FromInputValue for () {
|
||||||
fn from(_: &InputValue) -> Option<()> {
|
fn from_input_value(_: &InputValue) -> Option<()> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,7 +131,7 @@ impl GraphQLType for DogCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromInputValue for DogCommand {
|
impl FromInputValue for DogCommand {
|
||||||
fn from(v: &InputValue) -> Option<DogCommand> {
|
fn from_input_value(v: &InputValue) -> Option<DogCommand> {
|
||||||
match v.as_enum_value() {
|
match v.as_enum_value() {
|
||||||
Some("SIT") => Some(DogCommand::Sit),
|
Some("SIT") => Some(DogCommand::Sit),
|
||||||
Some("HEEL") => Some(DogCommand::Heel),
|
Some("HEEL") => Some(DogCommand::Heel),
|
||||||
|
@ -204,7 +204,7 @@ impl GraphQLType for FurColor {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromInputValue for FurColor {
|
impl FromInputValue for FurColor {
|
||||||
fn from(v: &InputValue) -> Option<FurColor> {
|
fn from_input_value(v: &InputValue) -> Option<FurColor> {
|
||||||
match v.as_enum_value() {
|
match v.as_enum_value() {
|
||||||
Some("BROWN") => Some(FurColor::Brown),
|
Some("BROWN") => Some(FurColor::Brown),
|
||||||
Some("BLACK") => Some(FurColor::Black),
|
Some("BLACK") => Some(FurColor::Black),
|
||||||
|
@ -382,7 +382,7 @@ impl GraphQLType for ComplexInput {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromInputValue for ComplexInput {
|
impl FromInputValue for ComplexInput {
|
||||||
fn from(v: &InputValue) -> Option<ComplexInput> {
|
fn from_input_value(v: &InputValue) -> Option<ComplexInput> {
|
||||||
let obj = match v.to_object_value() {
|
let obj = match v.to_object_value() {
|
||||||
Some(o) => o,
|
Some(o) => o,
|
||||||
None => return None,
|
None => return None,
|
||||||
|
|
|
@ -172,7 +172,7 @@ pub fn impl_enum(ast: &syn::DeriveInput) -> Tokens {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ::juniper::FromInputValue for #ident {
|
impl ::juniper::FromInputValue for #ident {
|
||||||
fn from(v: &::juniper::InputValue) -> Option<#ident> {
|
fn from_input_value(v: &::juniper::InputValue) -> Option<#ident> {
|
||||||
match v.as_enum_value().or_else(|| v.as_string_value()) {
|
match v.as_enum_value().or_else(|| v.as_string_value()) {
|
||||||
#(#from_inputs)*
|
#(#from_inputs)*
|
||||||
_ => None,
|
_ => None,
|
||||||
|
|
|
@ -169,8 +169,8 @@ pub fn impl_input_object(ast: &syn::DeriveInput) -> Tokens {
|
||||||
// TODO: investigate the unwraps here, they seem dangerous!
|
// TODO: investigate the unwraps here, they seem dangerous!
|
||||||
match obj.get(#name) {
|
match obj.get(#name) {
|
||||||
#from_input_default
|
#from_input_default
|
||||||
Some(v) => ::juniper::FromInputValue::from(v).unwrap(),
|
Some(v) => ::juniper::FromInputValue::from_input_value(v).unwrap(),
|
||||||
_ => ::juniper::FromInputValue::from(&::juniper::InputValue::null()).unwrap()
|
_ => ::juniper::FromInputValue::from_input_value(&::juniper::InputValue::null()).unwrap()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -203,7 +203,7 @@ pub fn impl_input_object(ast: &syn::DeriveInput) -> Tokens {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ::juniper::FromInputValue for #ident {
|
impl ::juniper::FromInputValue for #ident {
|
||||||
fn from(value: &::juniper::InputValue) -> Option<#ident> {
|
fn from_input_value(value: &::juniper::InputValue) -> Option<#ident> {
|
||||||
if let Some(obj) = value.to_object_value() {
|
if let Some(obj) = value.to_object_value() {
|
||||||
let item = #ident {
|
let item = #ident {
|
||||||
#(#from_inputs)*
|
#(#from_inputs)*
|
||||||
|
|
|
@ -28,14 +28,14 @@ fn test_derived_enum() {
|
||||||
// Test Regular variant.
|
// Test Regular variant.
|
||||||
assert_eq!(SomeEnum::Regular.to(), InputValue::String("REGULAR".into()));
|
assert_eq!(SomeEnum::Regular.to(), InputValue::String("REGULAR".into()));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
FromInputValue::from(&InputValue::String("REGULAR".into())),
|
FromInputValue::from_input_value(&InputValue::String("REGULAR".into())),
|
||||||
Some(SomeEnum::Regular)
|
Some(SomeEnum::Regular)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Test FULL variant.
|
// Test FULL variant.
|
||||||
assert_eq!(SomeEnum::Full.to(), InputValue::String("FULL".into()));
|
assert_eq!(SomeEnum::Full.to(), InputValue::String("FULL".into()));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
FromInputValue::from(&InputValue::String("FULL".into())),
|
FromInputValue::from_input_value(&InputValue::String("FULL".into())),
|
||||||
Some(SomeEnum::Full)
|
Some(SomeEnum::Full)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,6 @@ fn test_derived_input_object() {
|
||||||
regular_field: "a".to_string(),
|
regular_field: "a".to_string(),
|
||||||
c: 33,
|
c: 33,
|
||||||
};
|
};
|
||||||
let restored: Input = FromInputValue::from(&obj.to()).unwrap();
|
let restored: Input = FromInputValue::from_input_value(&obj.to()).unwrap();
|
||||||
assert_eq!(obj, restored);
|
assert_eq!(obj, restored);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue