Merge pull request #559 from bram209/feature/rust_decimal_scalar
Add Decimal scalar (from 'rust_decimal' crate)
This commit is contained in:
commit
57ae8bcb98
@ -20,6 +20,7 @@ unblock = ["blocking"]
|
|||||||
string_number = ["num-traits"]
|
string_number = ["num-traits"]
|
||||||
dataloader = ["futures-timer", "futures-channel", "lru"]
|
dataloader = ["futures-timer", "futures-channel", "lru"]
|
||||||
tracing = ["tracinglib", "tracing-futures"]
|
tracing = ["tracinglib", "tracing-futures"]
|
||||||
|
decimal = ["rust_decimal"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
async-graphql-derive = { path = "derive", version = "=2.9.5" }
|
async-graphql-derive = { path = "derive", version = "=2.9.5" }
|
||||||
@ -53,6 +54,7 @@ tracing-futures = { version = "0.2.5", optional = true, features = ["std-future"
|
|||||||
opentelemetry = { version = "0.13.0", optional = true }
|
opentelemetry = { version = "0.13.0", optional = true }
|
||||||
url = { version = "2.2.1", optional = true }
|
url = { version = "2.2.1", optional = true }
|
||||||
uuid = { version = "0.8.2", optional = true, features = ["v4", "serde"] }
|
uuid = { version = "0.8.2", optional = true, features = ["v4", "serde"] }
|
||||||
|
rust_decimal = { version = "1.14.3", optional = true }
|
||||||
|
|
||||||
# Non-feature optional dependencies
|
# Non-feature optional dependencies
|
||||||
blocking = { version = "1.0.2", optional = true }
|
blocking = { version = "1.0.2", optional = true }
|
||||||
|
@ -76,6 +76,7 @@ This crate offers the following features, all of which are not activated by defa
|
|||||||
- `string_number`: Enable the [StringNumber](types/struct.StringNumber.html).
|
- `string_number`: Enable the [StringNumber](types/struct.StringNumber.html).
|
||||||
- `dataloader`: Support [DataLoader](dataloader/struct.DataLoader.html).
|
- `dataloader`: Support [DataLoader](dataloader/struct.DataLoader.html).
|
||||||
- `secrecy`: Integrate with the [`secrecy` crate](https://crates.io/crates/secrecy).
|
- `secrecy`: Integrate with the [`secrecy` crate](https://crates.io/crates/secrecy).
|
||||||
|
- `decimal`: Integrate with the [`rust_decimal` crate](https://crates.io/crates/rust_decimal).
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
|
@ -71,6 +71,7 @@
|
|||||||
//! - `uuid`: Integrate with the [`uuid` crate](https://crates.io/crates/uuid).
|
//! - `uuid`: Integrate with the [`uuid` crate](https://crates.io/crates/uuid).
|
||||||
//! - `string_number`: Enable the [StringNumber](types/struct.StringNumber.html).
|
//! - `string_number`: Enable the [StringNumber](types/struct.StringNumber.html).
|
||||||
//! - `dataloader`: Support [DataLoader](dataloader/struct.DataLoader.html).
|
//! - `dataloader`: Support [DataLoader](dataloader/struct.DataLoader.html).
|
||||||
|
//! - `decimal`: Integrate with the [`rust_decimal` crate](https://crates.io/crates/rust_decimal).
|
||||||
//!
|
//!
|
||||||
//! ## Integrations
|
//! ## Integrations
|
||||||
//!
|
//!
|
||||||
|
19
src/types/external/decimal.rs
vendored
Normal file
19
src/types/external/decimal.rs
vendored
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
|
use rust_decimal::Decimal;
|
||||||
|
|
||||||
|
use crate::{InputValueError, InputValueResult, Scalar, ScalarType, Value};
|
||||||
|
|
||||||
|
#[Scalar(internal, name = "Decimal")]
|
||||||
|
impl ScalarType for Decimal {
|
||||||
|
fn parse(value: Value) -> InputValueResult<Self> {
|
||||||
|
match &value {
|
||||||
|
Value::String(s) => Ok(Decimal::from_str(s)?),
|
||||||
|
_ => Err(InputValueError::expected_type(value)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn to_value(&self) -> Value {
|
||||||
|
Value::String(self.to_string())
|
||||||
|
}
|
||||||
|
}
|
2
src/types/external/mod.rs
vendored
2
src/types/external/mod.rs
vendored
@ -17,6 +17,8 @@ mod bson;
|
|||||||
mod chrono_tz;
|
mod chrono_tz;
|
||||||
#[cfg(feature = "chrono")]
|
#[cfg(feature = "chrono")]
|
||||||
mod datetime;
|
mod datetime;
|
||||||
|
#[cfg(feature = "decimal")]
|
||||||
|
mod decimal;
|
||||||
#[cfg(feature = "chrono")]
|
#[cfg(feature = "chrono")]
|
||||||
mod naive_time;
|
mod naive_time;
|
||||||
#[cfg(feature = "secrecy")]
|
#[cfg(feature = "secrecy")]
|
||||||
|
Loading…
Reference in New Issue
Block a user