Use value!
instead of serde_json::json!
.
This commit is contained in:
parent
a575c9fe1e
commit
b0ceb58163
|
@ -186,6 +186,16 @@ impl<'a> QueryPathNode<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Get the path represented by `Vec<String>`.
|
||||
pub fn to_string_vec(&self) -> Vec<String> {
|
||||
let mut res = Vec::new();
|
||||
self.for_each(|s| match s {
|
||||
QueryPathSegment::Index(idx) => res.push(format!("{}", idx)),
|
||||
QueryPathSegment::Name(name) => res.push(name.to_string()),
|
||||
});
|
||||
res
|
||||
}
|
||||
|
||||
pub(crate) fn for_each<F: FnMut(&QueryPathSegment<'a>)>(&self, mut f: F) {
|
||||
self.for_each_ref(&mut f);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
//! Apollo persisted queries extension.
|
||||
|
||||
use crate::extensions::{Extension, ExtensionContext, ExtensionFactory};
|
||||
use crate::{Request, ServerError, ServerResult};
|
||||
use crate::{from_value, Request, ServerError, ServerResult};
|
||||
use futures::lock::Mutex;
|
||||
use serde::Deserialize;
|
||||
use std::sync::Arc;
|
||||
|
@ -80,7 +80,7 @@ impl<T: CacheStorage> Extension for ApolloPersistedQueriesExtension<T> {
|
|||
mut request: Request,
|
||||
) -> ServerResult<Request> {
|
||||
if let Some(value) = request.extensions.remove("persistedQuery") {
|
||||
let persisted_query: PersistedQuery = serde_json::from_value(value).map_err(|_| {
|
||||
let persisted_query: PersistedQuery = from_value(value).map_err(|_| {
|
||||
ServerError::new("Invalid \"PersistedQuery\" extension configuration.")
|
||||
})?;
|
||||
if persisted_query.version != 1 {
|
||||
|
@ -130,7 +130,7 @@ mod tests {
|
|||
let mut request = Request::new("{ value }");
|
||||
request.extensions.insert(
|
||||
"persistedQuery".to_string(),
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"version": 1,
|
||||
"sha256Hash": "abc",
|
||||
}),
|
||||
|
@ -138,7 +138,7 @@ mod tests {
|
|||
|
||||
assert_eq!(
|
||||
schema.execute(request).await.into_result().unwrap().data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"value": 100
|
||||
})
|
||||
);
|
||||
|
@ -146,7 +146,7 @@ mod tests {
|
|||
let mut request = Request::new("");
|
||||
request.extensions.insert(
|
||||
"persistedQuery".to_string(),
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"version": 1,
|
||||
"sha256Hash": "abc",
|
||||
}),
|
||||
|
@ -154,7 +154,7 @@ mod tests {
|
|||
|
||||
assert_eq!(
|
||||
schema.execute(request).await.into_result().unwrap().data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"value": 100
|
||||
})
|
||||
);
|
||||
|
@ -162,7 +162,7 @@ mod tests {
|
|||
let mut request = Request::new("");
|
||||
request.extensions.insert(
|
||||
"persistedQuery".to_string(),
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"version": 1,
|
||||
"sha256Hash": "def",
|
||||
}),
|
||||
|
|
|
@ -1,14 +1,13 @@
|
|||
use crate::extensions::{Extension, ExtensionContext, ExtensionFactory, ResolveInfo};
|
||||
use crate::{Value, Variables};
|
||||
use crate::{value, Value, Variables};
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::ser::SerializeMap;
|
||||
use serde::{Serialize, Serializer};
|
||||
use std::collections::BTreeMap;
|
||||
use std::convert::TryInto;
|
||||
use std::ops::Deref;
|
||||
|
||||
struct PendingResolve {
|
||||
path: serde_json::Value,
|
||||
path: Vec<String>,
|
||||
field_name: String,
|
||||
parent_type: String,
|
||||
return_type: String,
|
||||
|
@ -95,7 +94,7 @@ impl Extension for ApolloTracingExtension {
|
|||
self.pending_resolves.insert(
|
||||
info.resolve_id.current,
|
||||
PendingResolve {
|
||||
path: serde_json::to_value(info.path_node).unwrap(),
|
||||
path: info.path_node.to_string_vec(),
|
||||
field_name: info.path_node.field_name().to_string(),
|
||||
parent_type: info.parent_type.to_string(),
|
||||
return_type: info.return_type.to_string(),
|
||||
|
@ -121,7 +120,7 @@ impl Extension for ApolloTracingExtension {
|
|||
self.resolves
|
||||
.sort_by(|a, b| a.start_offset.cmp(&b.start_offset));
|
||||
|
||||
serde_json::json!({
|
||||
Some(value!({
|
||||
"version": 1,
|
||||
"startTime": self.start_time.to_rfc3339(),
|
||||
"endTime": self.end_time.to_rfc3339(),
|
||||
|
@ -129,8 +128,6 @@ impl Extension for ApolloTracingExtension {
|
|||
"execution": {
|
||||
"resolvers": self.resolves
|
||||
}
|
||||
})
|
||||
.try_into()
|
||||
.ok()
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
|
12
src/lib.rs
12
src/lib.rs
|
@ -285,7 +285,7 @@ pub use types::*;
|
|||
/// valueWithArg1: valueWithArg
|
||||
/// valueWithArg2: valueWithArg(a: 99)
|
||||
/// }"#).await.into_result().unwrap().data;
|
||||
/// assert_eq!(res, serde_json::json!({
|
||||
/// assert_eq!(res, value!({
|
||||
/// "value": 10,
|
||||
/// "valueRef": 10,
|
||||
/// "valueWithError": 10,
|
||||
|
@ -337,7 +337,7 @@ pub use async_graphql_derive::Object;
|
|||
/// async_std::task::block_on(async move {
|
||||
/// let schema = Schema::new(QueryRoot{ value: 10 }, EmptyMutation, EmptySubscription);
|
||||
/// let res = schema.execute("{ value }").await.into_result().unwrap().data;
|
||||
/// assert_eq!(res, serde_json::json!({
|
||||
/// assert_eq!(res, value!({
|
||||
/// "value": 10,
|
||||
/// }));
|
||||
/// });
|
||||
|
@ -394,7 +394,7 @@ pub use async_graphql_derive::SimpleObject;
|
|||
/// async_std::task::block_on(async move {
|
||||
/// let schema = Schema::new(QueryRoot{ value1: MyEnum::A, value2: MyEnum::B }, EmptyMutation, EmptySubscription);
|
||||
/// let res = schema.execute("{ value1 value2 }").await.into_result().unwrap().data;
|
||||
/// assert_eq!(res, serde_json::json!({ "value1": "A", "value2": "b" }));
|
||||
/// assert_eq!(res, value!({ "value1": "A", "value2": "b" }));
|
||||
/// });
|
||||
/// ```
|
||||
pub use async_graphql_derive::Enum;
|
||||
|
@ -449,7 +449,7 @@ pub use async_graphql_derive::Enum;
|
|||
/// value1: value(input:{a:9, b:3})
|
||||
/// value2: value(input:{a:9})
|
||||
/// }"#).await.into_result().unwrap().data;
|
||||
/// assert_eq!(res, serde_json::json!({ "value1": 27, "value2": 90 }));
|
||||
/// assert_eq!(res, value!({ "value1": 27, "value2": 90 }));
|
||||
/// });
|
||||
/// ```
|
||||
pub use async_graphql_derive::InputObject;
|
||||
|
@ -574,7 +574,7 @@ pub use async_graphql_derive::InputObject;
|
|||
/// value_d
|
||||
/// }
|
||||
/// }"#).await.into_result().unwrap().data;
|
||||
/// assert_eq!(res, serde_json::json!({
|
||||
/// assert_eq!(res, value!({
|
||||
/// "typeA": {
|
||||
/// "valueA": "hello",
|
||||
/// "valueB": 10,
|
||||
|
@ -647,7 +647,7 @@ pub use async_graphql_derive::Interface;
|
|||
/// }
|
||||
/// }
|
||||
/// }"#).await.into_result().unwrap().data;
|
||||
/// assert_eq!(res, serde_json::json!({
|
||||
/// assert_eq!(res, value!({
|
||||
/// "allData": [
|
||||
/// { "valueA": 10 },
|
||||
/// { "valueB": 20 },
|
||||
|
|
|
@ -35,7 +35,7 @@ pub struct Request {
|
|||
|
||||
/// The extensions config of the request.
|
||||
#[serde(default)]
|
||||
pub extensions: HashMap<String, serde_json::Value>,
|
||||
pub extensions: HashMap<String, Value>,
|
||||
}
|
||||
|
||||
fn deserialize_variables<'de, D: Deserializer<'de>>(
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use crate::{InputValueResult, Scalar, ScalarType, Value};
|
||||
use serde::de::DeserializeOwned;
|
||||
|
||||
/// Any scalar (For [Apollo Federation](https://www.apollographql.com/docs/apollo-server/federation/introduction))
|
||||
///
|
||||
|
@ -23,13 +22,6 @@ impl ScalarType for Any {
|
|||
}
|
||||
}
|
||||
|
||||
impl Any {
|
||||
/// Parse this `Any` value to T by `serde_json`.
|
||||
pub fn parse_value<T: DeserializeOwned>(&self) -> serde_json::Result<T> {
|
||||
serde_json::from_value(self.to_value().into_json()?)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Into<Value>> From<T> for Any {
|
||||
fn from(value: T) -> Any {
|
||||
Any(value.into())
|
||||
|
|
|
@ -70,7 +70,7 @@ pub struct EmptyFields;
|
|||
/// async fn main() {
|
||||
/// let schema = Schema::new(QueryRoot, EmptyMutation, EmptySubscription);
|
||||
///
|
||||
/// assert_eq!(schema.execute("{ numbers(first: 2) { edges { node diff } } }").await.into_result().unwrap().data, serde_json::json!({
|
||||
/// assert_eq!(schema.execute("{ numbers(first: 2) { edges { node diff } } }").await.into_result().unwrap().data, value!({
|
||||
/// "numbers": {
|
||||
/// "edges": [
|
||||
/// {"node": 0, "diff": 10000},
|
||||
|
@ -79,7 +79,7 @@ pub struct EmptyFields;
|
|||
/// },
|
||||
/// }));
|
||||
///
|
||||
/// assert_eq!(schema.execute("{ numbers(last: 2) { edges { node diff } } }").await.into_result().unwrap().data, serde_json::json!({
|
||||
/// assert_eq!(schema.execute("{ numbers(last: 2) { edges { node diff } } }").await.into_result().unwrap().data, value!({
|
||||
/// "numbers": {
|
||||
/// "edges": [
|
||||
/// {"node": 9998, "diff": 2},
|
||||
|
|
18
src/types/external/integers.rs
vendored
18
src/types/external/integers.rs
vendored
|
@ -1,4 +1,4 @@
|
|||
use crate::{InputValueError, InputValueResult, Scalar, ScalarType, Value};
|
||||
use crate::{InputValueError, InputValueResult, Number, Scalar, ScalarType, Value};
|
||||
|
||||
/// The `Int` scalar type represents non-fractional whole numeric values.
|
||||
#[Scalar(internal, name = "Int")]
|
||||
|
@ -30,7 +30,7 @@ impl ScalarType for i8 {
|
|||
}
|
||||
|
||||
fn to_value(&self) -> Value {
|
||||
Value::Number(serde_json::Number::from(*self as i64))
|
||||
Value::Number(Number::from(*self as i64))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -64,7 +64,7 @@ impl ScalarType for i16 {
|
|||
}
|
||||
|
||||
fn to_value(&self) -> Value {
|
||||
Value::Number(serde_json::Number::from(*self as i64))
|
||||
Value::Number(Number::from(*self as i64))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -98,7 +98,7 @@ impl ScalarType for i32 {
|
|||
}
|
||||
|
||||
fn to_value(&self) -> Value {
|
||||
Value::Number(serde_json::Number::from(*self as i64))
|
||||
Value::Number(Number::from(*self as i64))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -132,7 +132,7 @@ impl ScalarType for i64 {
|
|||
}
|
||||
|
||||
fn to_value(&self) -> Value {
|
||||
Value::Number(serde_json::Number::from(*self as i64))
|
||||
Value::Number(Number::from(*self as i64))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -166,7 +166,7 @@ impl ScalarType for u8 {
|
|||
}
|
||||
|
||||
fn to_value(&self) -> Value {
|
||||
Value::Number(serde_json::Number::from(*self as u64))
|
||||
Value::Number(Number::from(*self as u64))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -200,7 +200,7 @@ impl ScalarType for u16 {
|
|||
}
|
||||
|
||||
fn to_value(&self) -> Value {
|
||||
Value::Number(serde_json::Number::from(*self as u64))
|
||||
Value::Number(Number::from(*self as u64))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -234,7 +234,7 @@ impl ScalarType for u32 {
|
|||
}
|
||||
|
||||
fn to_value(&self) -> Value {
|
||||
Value::Number(serde_json::Number::from(*self as u64))
|
||||
Value::Number(Number::from(*self as u64))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -268,6 +268,6 @@ impl ScalarType for u64 {
|
|||
}
|
||||
|
||||
fn to_value(&self) -> Value {
|
||||
Value::Number(serde_json::Number::from(*self as u64))
|
||||
Value::Number(Number::from(*self as u64))
|
||||
}
|
||||
}
|
||||
|
|
18
src/types/external/non_zero_integers.rs
vendored
18
src/types/external/non_zero_integers.rs
vendored
|
@ -1,4 +1,4 @@
|
|||
use crate::{InputValueError, InputValueResult, Scalar, ScalarType, Value};
|
||||
use crate::{InputValueError, InputValueResult, Number, Scalar, ScalarType, Value};
|
||||
use std::num::{
|
||||
NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI8, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8,
|
||||
};
|
||||
|
@ -33,7 +33,7 @@ impl ScalarType for NonZeroI8 {
|
|||
}
|
||||
|
||||
fn to_value(&self) -> Value {
|
||||
Value::Number(serde_json::Number::from(self.get() as i64))
|
||||
Value::Number(Number::from(self.get() as i64))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ impl ScalarType for NonZeroI16 {
|
|||
}
|
||||
|
||||
fn to_value(&self) -> Value {
|
||||
Value::Number(serde_json::Number::from(self.get() as i64))
|
||||
Value::Number(Number::from(self.get() as i64))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -101,7 +101,7 @@ impl ScalarType for NonZeroI32 {
|
|||
}
|
||||
|
||||
fn to_value(&self) -> Value {
|
||||
Value::Number(serde_json::Number::from(self.get() as i64))
|
||||
Value::Number(Number::from(self.get() as i64))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -135,7 +135,7 @@ impl ScalarType for NonZeroI64 {
|
|||
}
|
||||
|
||||
fn to_value(&self) -> Value {
|
||||
Value::Number(serde_json::Number::from(self.get() as i64))
|
||||
Value::Number(Number::from(self.get() as i64))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -169,7 +169,7 @@ impl ScalarType for NonZeroU8 {
|
|||
}
|
||||
|
||||
fn to_value(&self) -> Value {
|
||||
Value::Number(serde_json::Number::from(self.get() as u64))
|
||||
Value::Number(Number::from(self.get() as u64))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -203,7 +203,7 @@ impl ScalarType for NonZeroU16 {
|
|||
}
|
||||
|
||||
fn to_value(&self) -> Value {
|
||||
Value::Number(serde_json::Number::from(self.get() as u64))
|
||||
Value::Number(Number::from(self.get() as u64))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -237,7 +237,7 @@ impl ScalarType for NonZeroU32 {
|
|||
}
|
||||
|
||||
fn to_value(&self) -> Value {
|
||||
Value::Number(serde_json::Number::from(self.get() as u64))
|
||||
Value::Number(Number::from(self.get() as u64))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -271,6 +271,6 @@ impl ScalarType for NonZeroU64 {
|
|||
}
|
||||
|
||||
fn to_value(&self) -> Value {
|
||||
Value::Number(serde_json::Number::from(self.get() as u64))
|
||||
Value::Number(Number::from(self.get() as u64))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
use crate::parser::types::Field;
|
||||
use crate::registry::{MetaType, Registry};
|
||||
use crate::{
|
||||
ContextSelectionSet, InputValueResult, OutputValueType, Positioned, Scalar, ScalarType,
|
||||
ServerResult, Type, Value,
|
||||
from_value, to_value, ContextSelectionSet, InputValueResult, OutputValueType, Positioned,
|
||||
Scalar, ScalarType, ServerResult, Type, Value,
|
||||
};
|
||||
use serde::de::DeserializeOwned;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::borrow::Cow;
|
||||
use std::convert::TryInto;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
|
||||
/// A scalar that can represent any JSON value.
|
||||
|
@ -41,14 +40,11 @@ impl<T: DeserializeOwned + Serialize> From<T> for Json<T> {
|
|||
#[Scalar(internal, name = "JSON")]
|
||||
impl<T: DeserializeOwned + Serialize + Send + Sync> ScalarType for Json<T> {
|
||||
fn parse(value: Value) -> InputValueResult<Self> {
|
||||
Ok(serde_json::from_value(value.into_json()?)?)
|
||||
Ok(from_value(value)?)
|
||||
}
|
||||
|
||||
fn to_value(&self) -> Value {
|
||||
serde_json::to_value(&self.0)
|
||||
.ok()
|
||||
.and_then(|json| Value::from_json(json).ok())
|
||||
.unwrap_or_else(|| Value::Null)
|
||||
to_value(&self.0).unwrap_or_else(|_| Value::Null)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -97,10 +93,7 @@ impl<T: Serialize + Send + Sync> OutputValueType for OutputJson<T> {
|
|||
_ctx: &ContextSelectionSet<'_>,
|
||||
_field: &Positioned<Field>,
|
||||
) -> ServerResult<Value> {
|
||||
Ok(serde_json::to_value(&self.0)
|
||||
.ok()
|
||||
.and_then(|json| json.try_into().ok())
|
||||
.unwrap_or_else(|| Value::Null))
|
||||
Ok(to_value(&self.0).ok().unwrap_or_else(|| Value::Null))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -132,7 +125,7 @@ mod test {
|
|||
let schema = Schema::new(Query, EmptyMutation, EmptySubscription);
|
||||
assert_eq!(
|
||||
schema.execute(query).await.into_result().unwrap().data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"obj": {
|
||||
"a": 1,
|
||||
"b": 2,
|
||||
|
@ -174,7 +167,7 @@ mod test {
|
|||
let schema = Schema::new(Query, EmptyMutation, EmptySubscription);
|
||||
assert_eq!(
|
||||
schema.execute(query).await.into_result().unwrap().data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"obj": {
|
||||
"a": 1,
|
||||
"b": 2,
|
||||
|
|
|
@ -37,7 +37,7 @@ use std::borrow::Cow;
|
|||
/// }"#;
|
||||
/// assert_eq!(
|
||||
/// schema.execute(query).await.into_result().unwrap().data,
|
||||
/// serde_json::json!({
|
||||
/// value!({
|
||||
/// "v1": 99,
|
||||
/// "v2": 1,
|
||||
/// "v3": 2,
|
||||
|
@ -183,16 +183,16 @@ mod tests {
|
|||
#[test]
|
||||
fn test_maybe_undefined_serde() {
|
||||
assert_eq!(
|
||||
serde_json::to_string(&MaybeUndefined::Value(100i32)).unwrap(),
|
||||
"100"
|
||||
to_value(&MaybeUndefined::Value(100i32)).unwrap(),
|
||||
value!(100)
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
serde_json::from_str::<MaybeUndefined<i32>>("100").unwrap(),
|
||||
from_value::<MaybeUndefined<i32>>(value!(100)).unwrap(),
|
||||
MaybeUndefined::Value(100)
|
||||
);
|
||||
assert_eq!(
|
||||
serde_json::from_str::<MaybeUndefined<i32>>("null").unwrap(),
|
||||
from_value::<MaybeUndefined<i32>>(value!(null)).unwrap(),
|
||||
MaybeUndefined::Null
|
||||
);
|
||||
|
||||
|
@ -202,45 +202,45 @@ mod tests {
|
|||
}
|
||||
|
||||
assert_eq!(
|
||||
serde_json::to_string(&A {
|
||||
to_value(&A {
|
||||
a: MaybeUndefined::Value(100i32)
|
||||
})
|
||||
.unwrap(),
|
||||
r#"{"a":100}"#
|
||||
value!({"a": 100})
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
serde_json::to_string(&A {
|
||||
to_value(&A {
|
||||
a: MaybeUndefined::Null,
|
||||
})
|
||||
.unwrap(),
|
||||
r#"{"a":null}"#
|
||||
value!({ "a": null })
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
serde_json::to_string(&A {
|
||||
to_value(&A {
|
||||
a: MaybeUndefined::Undefined,
|
||||
})
|
||||
.unwrap(),
|
||||
r#"{"a":null}"#
|
||||
value!({ "a": null })
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
serde_json::from_str::<A>(r#"{"a":100}"#).unwrap(),
|
||||
from_value::<A>(value!({"a": 100})).unwrap(),
|
||||
A {
|
||||
a: MaybeUndefined::Value(100i32)
|
||||
}
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
serde_json::from_str::<A>(r#"{"a":null}"#).unwrap(),
|
||||
from_value::<A>(value!({ "a": null })).unwrap(),
|
||||
A {
|
||||
a: MaybeUndefined::Null
|
||||
}
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
serde_json::from_str::<A>(r#"{}"#).unwrap(),
|
||||
from_value::<A>(value!({})).unwrap(),
|
||||
A {
|
||||
a: MaybeUndefined::Null
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ mod test {
|
|||
.into_result()
|
||||
.unwrap()
|
||||
.data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"value1": "100",
|
||||
"value2": "-100",
|
||||
"value3": "0",
|
||||
|
|
|
@ -52,7 +52,7 @@ pub async fn test_complexity_and_depth() {
|
|||
.finish();
|
||||
assert_eq!(
|
||||
schema.execute(query).await.data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"a": 1,
|
||||
"b": 1,
|
||||
})
|
||||
|
@ -78,7 +78,7 @@ pub async fn test_complexity_and_depth() {
|
|||
.finish();
|
||||
assert_eq!(
|
||||
schema.execute(query).await.data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"obj": { "a": 1 }
|
||||
})
|
||||
);
|
||||
|
@ -121,7 +121,7 @@ pub async fn test_complexity_and_depth() {
|
|||
.finish();
|
||||
assert_eq!(
|
||||
schema.execute(query).await.data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"obj": {
|
||||
"a": 1,
|
||||
"b": 2,
|
||||
|
|
|
@ -66,7 +66,7 @@ pub async fn test_connection_additional_fields() {
|
|||
.execute("{ numbers(first: 2) { totalCount edges { node diff } } }")
|
||||
.await
|
||||
.data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"numbers": {
|
||||
"totalCount": 10000,
|
||||
"edges": [
|
||||
|
@ -82,7 +82,7 @@ pub async fn test_connection_additional_fields() {
|
|||
.execute("{ numbers(last: 2) { edges { node diff } } }")
|
||||
.await
|
||||
.data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"numbers": {
|
||||
"edges": [
|
||||
{"node": 9998, "diff": 2},
|
||||
|
|
|
@ -23,7 +23,7 @@ pub async fn test_default_value_arg() {
|
|||
let schema = Schema::new(Query, EmptyMutation, EmptySubscription);
|
||||
assert_eq!(
|
||||
schema.execute(query).await.data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"value1": 100,
|
||||
"value2": 0,
|
||||
"value3": 6,
|
||||
|
@ -34,7 +34,7 @@ pub async fn test_default_value_arg() {
|
|||
let schema = Schema::new(Query, EmptyMutation, EmptySubscription);
|
||||
assert_eq!(
|
||||
schema.execute(query).await.data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"value1": 1,
|
||||
"value2": 2,
|
||||
"value3": 3,
|
||||
|
@ -80,7 +80,7 @@ pub async fn test_default_value_inputobject() {
|
|||
let schema = Schema::new(Query, EmptyMutation, EmptySubscription);
|
||||
assert_eq!(
|
||||
schema.execute(query).await.data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"value": {
|
||||
"value1": 100,
|
||||
"value2": 0,
|
||||
|
@ -93,7 +93,7 @@ pub async fn test_default_value_inputobject() {
|
|||
let schema = Schema::new(Query, EmptyMutation, EmptySubscription);
|
||||
assert_eq!(
|
||||
schema.execute(query).await.data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"value": {
|
||||
"value1": 1,
|
||||
"value2": 2,
|
||||
|
|
|
@ -24,7 +24,7 @@ pub async fn test_directive_skip() {
|
|||
.await;
|
||||
assert_eq!(
|
||||
resp.data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"value2": 10,
|
||||
})
|
||||
);
|
||||
|
@ -54,7 +54,7 @@ pub async fn test_directive_include() {
|
|||
.await;
|
||||
assert_eq!(
|
||||
resp.data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"value1": 10,
|
||||
})
|
||||
);
|
||||
|
@ -93,7 +93,7 @@ pub async fn test_directive_ifdef() {
|
|||
.await;
|
||||
assert_eq!(
|
||||
resp.data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"value1": 10,
|
||||
})
|
||||
);
|
||||
|
@ -110,7 +110,7 @@ pub async fn test_directive_ifdef() {
|
|||
.await;
|
||||
assert_eq!(
|
||||
resp.data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"action1": 10,
|
||||
})
|
||||
);
|
||||
|
|
|
@ -41,7 +41,7 @@ pub async fn test_enum_type() {
|
|||
.to_owned();
|
||||
assert_eq!(
|
||||
schema.execute(&query).await.data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"value": "A",
|
||||
"testArg": "A",
|
||||
"testInput": "B",
|
||||
|
|
|
@ -80,7 +80,7 @@ pub async fn test_federation() {
|
|||
}"#;
|
||||
assert_eq!(
|
||||
schema.execute(query).await.into_result().unwrap().data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"_entities": [
|
||||
{"__typename": "Product", "upc": "B00005N5PF"},
|
||||
]
|
||||
|
|
|
@ -68,7 +68,7 @@ pub async fn test_field_features() {
|
|||
let query = "{ value }";
|
||||
assert_eq!(
|
||||
schema.execute(query).await.data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"value": 10,
|
||||
})
|
||||
);
|
||||
|
@ -76,7 +76,7 @@ pub async fn test_field_features() {
|
|||
let query = "{ valueBson }";
|
||||
assert_eq!(
|
||||
schema.execute(query).await.data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"valueBson": 10,
|
||||
})
|
||||
);
|
||||
|
@ -96,7 +96,7 @@ pub async fn test_field_features() {
|
|||
let query = "{ obj { value } }";
|
||||
assert_eq!(
|
||||
schema.execute(query).await.data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"obj": { "value": 10 }
|
||||
})
|
||||
);
|
||||
|
@ -104,7 +104,7 @@ pub async fn test_field_features() {
|
|||
let query = "{ obj { valueBson } }";
|
||||
assert_eq!(
|
||||
schema.execute(query).await.data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"obj": { "valueBson": 10 }
|
||||
})
|
||||
);
|
||||
|
@ -128,7 +128,7 @@ pub async fn test_field_features() {
|
|||
.await
|
||||
.map(|resp| resp.into_result().unwrap().data)
|
||||
.unwrap(),
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"values": 10
|
||||
})
|
||||
);
|
||||
|
@ -136,7 +136,7 @@ pub async fn test_field_features() {
|
|||
let mut stream = schema.execute_stream("subscription { valuesBson }").boxed();
|
||||
assert_eq!(
|
||||
stream.next().await.map(|resp| resp.data).unwrap(),
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"valuesBson": 10
|
||||
})
|
||||
);
|
||||
|
|
|
@ -33,7 +33,7 @@ pub async fn test_field_merge() {
|
|||
"#;
|
||||
assert_eq!(
|
||||
schema.execute(query).await.data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"value1": 1,
|
||||
"value2": 2,
|
||||
"value3": 3,
|
||||
|
@ -73,7 +73,7 @@ pub async fn test_field_object_merge() {
|
|||
"#;
|
||||
assert_eq!(
|
||||
schema.execute(query).await.data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"obj": {
|
||||
"a": 1,
|
||||
"b": 2,
|
||||
|
|
|
@ -41,7 +41,7 @@ pub async fn test_generic_object() {
|
|||
.to_owned();
|
||||
assert_eq!(
|
||||
schema.execute(&query).await.into_result().unwrap().data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"objI32": {"value": 100},
|
||||
"objBool": {"value": true},
|
||||
})
|
||||
|
|
|
@ -83,7 +83,7 @@ pub async fn test_guard_simple_rule() {
|
|||
.execute(Request::new(query).data(Role::Admin))
|
||||
.await
|
||||
.data,
|
||||
serde_json::json!({"value": 10})
|
||||
value!({"value": 10})
|
||||
);
|
||||
|
||||
let query = "{ value }";
|
||||
|
@ -108,9 +108,9 @@ pub async fn test_guard_simple_rule() {
|
|||
.collect::<Vec<_>>()
|
||||
.await,
|
||||
vec![
|
||||
serde_json::json! ({"values": 1}),
|
||||
serde_json::json! ({"values": 2}),
|
||||
serde_json::json! ({"values": 3})
|
||||
value! ({"values": 1}),
|
||||
value! ({"values": 2}),
|
||||
value! ({"values": 3})
|
||||
]
|
||||
);
|
||||
|
||||
|
@ -157,7 +157,7 @@ pub async fn test_guard_and_operator() {
|
|||
)
|
||||
.await
|
||||
.data,
|
||||
serde_json::json!({"value": 10})
|
||||
value!({"value": 10})
|
||||
);
|
||||
|
||||
let query = "{ value }";
|
||||
|
@ -238,7 +238,7 @@ pub async fn test_guard_or_operator() {
|
|||
)
|
||||
.await
|
||||
.data,
|
||||
serde_json::json!({"value": 10})
|
||||
value!({"value": 10})
|
||||
);
|
||||
|
||||
let query = "{ value }";
|
||||
|
@ -251,7 +251,7 @@ pub async fn test_guard_or_operator() {
|
|||
)
|
||||
.await
|
||||
.data,
|
||||
serde_json::json!({"value": 10})
|
||||
value!({"value": 10})
|
||||
);
|
||||
|
||||
let query = "{ value }";
|
||||
|
@ -264,7 +264,7 @@ pub async fn test_guard_or_operator() {
|
|||
)
|
||||
.await
|
||||
.data,
|
||||
serde_json::json!({"value": 10})
|
||||
value!({"value": 10})
|
||||
);
|
||||
|
||||
let query = "{ value }";
|
||||
|
@ -312,7 +312,7 @@ pub async fn test_guard_chain_operator() {
|
|||
)
|
||||
.await
|
||||
.data,
|
||||
serde_json::json!({"value": 10})
|
||||
value!({"value": 10})
|
||||
);
|
||||
|
||||
let query = "{ value }";
|
||||
|
@ -421,7 +421,7 @@ pub async fn test_guard_race_operator() {
|
|||
)
|
||||
.await
|
||||
.data,
|
||||
serde_json::json!({"value": 10})
|
||||
value!({"value": 10})
|
||||
);
|
||||
|
||||
let query = "{ value }";
|
||||
|
@ -435,7 +435,7 @@ pub async fn test_guard_race_operator() {
|
|||
)
|
||||
.await
|
||||
.data,
|
||||
serde_json::json!({"value": 10})
|
||||
value!({"value": 10})
|
||||
);
|
||||
|
||||
let query = "{ value }";
|
||||
|
@ -449,7 +449,7 @@ pub async fn test_guard_race_operator() {
|
|||
)
|
||||
.await
|
||||
.data,
|
||||
serde_json::json!({"value": 10})
|
||||
value!({"value": 10})
|
||||
);
|
||||
|
||||
let query = "{ value }";
|
||||
|
@ -463,7 +463,7 @@ pub async fn test_guard_race_operator() {
|
|||
)
|
||||
.await
|
||||
.data,
|
||||
serde_json::json!({"value": 10})
|
||||
value!({"value": 10})
|
||||
);
|
||||
|
||||
let query = "{ value }";
|
||||
|
|
|
@ -75,7 +75,7 @@ pub async fn test_input_object_default_value() {
|
|||
.to_owned();
|
||||
assert_eq!(
|
||||
schema.execute(&query).await.data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"a": {
|
||||
"a": 999,
|
||||
"b": [1, 2, 3],
|
||||
|
@ -126,14 +126,11 @@ pub async fn test_inputobject_flatten_recursive() {
|
|||
}
|
||||
|
||||
assert_eq!(
|
||||
MyInputObject::parse(Some(
|
||||
Value::from_json(serde_json::json!({
|
||||
"a": 10,
|
||||
"b": 20,
|
||||
"c": 30,
|
||||
}))
|
||||
.unwrap()
|
||||
))
|
||||
MyInputObject::parse(Some(value!({
|
||||
"a": 10,
|
||||
"b": 20,
|
||||
"c": 30,
|
||||
})))
|
||||
.unwrap(),
|
||||
MyInputObject {
|
||||
b_obj: B {
|
||||
|
@ -153,12 +150,11 @@ pub async fn test_inputobject_flatten_recursive() {
|
|||
c: 30,
|
||||
}
|
||||
.to_value(),
|
||||
Value::from_json(serde_json::json!({
|
||||
value!({
|
||||
"a": 10,
|
||||
"b": 20,
|
||||
"c": 30,
|
||||
}))
|
||||
.unwrap()
|
||||
})
|
||||
);
|
||||
|
||||
struct Query;
|
||||
|
@ -196,7 +192,7 @@ pub async fn test_inputobject_flatten_recursive() {
|
|||
.into_result()
|
||||
.unwrap()
|
||||
.data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"test": 60,
|
||||
})
|
||||
);
|
||||
|
@ -212,7 +208,7 @@ pub async fn test_inputobject_flatten_recursive() {
|
|||
.into_result()
|
||||
.unwrap()
|
||||
.data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"test": 110,
|
||||
})
|
||||
);
|
||||
|
@ -228,7 +224,7 @@ pub async fn test_inputobject_flatten_recursive() {
|
|||
.into_result()
|
||||
.unwrap()
|
||||
.data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"testWithDefault": 6,
|
||||
})
|
||||
);
|
||||
|
@ -264,14 +260,11 @@ pub async fn test_inputobject_flatten_multiple() {
|
|||
}
|
||||
|
||||
assert_eq!(
|
||||
ABC::parse(Some(
|
||||
Value::from_json(serde_json::json!({
|
||||
"a": 10,
|
||||
"b": 20,
|
||||
"c": 30,
|
||||
}))
|
||||
.unwrap()
|
||||
))
|
||||
ABC::parse(Some(value!({
|
||||
"a": 10,
|
||||
"b": 20,
|
||||
"c": 30,
|
||||
})))
|
||||
.unwrap(),
|
||||
ABC {
|
||||
a: A { a: 10 },
|
||||
|
@ -287,11 +280,10 @@ pub async fn test_inputobject_flatten_multiple() {
|
|||
c: C { c: 30 }
|
||||
}
|
||||
.to_value(),
|
||||
Value::from_json(serde_json::json!({
|
||||
value!({
|
||||
"a": 10,
|
||||
"b": 20,
|
||||
"c": 30,
|
||||
}))
|
||||
.unwrap()
|
||||
})
|
||||
);
|
||||
}
|
||||
|
|
|
@ -100,7 +100,7 @@ pub async fn test_input_validator_string_min_length() {
|
|||
.into_result()
|
||||
.expect(&error_msg[..])
|
||||
.data,
|
||||
serde_json::json!({"fieldParameter": true}),
|
||||
value!({"fieldParameter": true}),
|
||||
"Failed to validate {} with StringMinLength",
|
||||
case
|
||||
);
|
||||
|
@ -112,7 +112,7 @@ pub async fn test_input_validator_string_min_length() {
|
|||
.into_result()
|
||||
.expect(&error_msg[..])
|
||||
.data,
|
||||
serde_json::json!({"inputObject": true}),
|
||||
value!({"inputObject": true}),
|
||||
"Failed to validate {} with StringMinLength",
|
||||
case
|
||||
);
|
||||
|
@ -210,7 +210,7 @@ pub async fn test_input_validator_string_max_length() {
|
|||
.into_result()
|
||||
.expect(&error_msg[..])
|
||||
.data,
|
||||
serde_json::json!({"fieldParameter": true}),
|
||||
value!({"fieldParameter": true}),
|
||||
"Failed to validate {} with StringMaxLength",
|
||||
case
|
||||
);
|
||||
|
@ -222,7 +222,7 @@ pub async fn test_input_validator_string_max_length() {
|
|||
.into_result()
|
||||
.expect(&error_msg[..])
|
||||
.data,
|
||||
serde_json::json!({"inputObject": true}),
|
||||
value!({"inputObject": true}),
|
||||
"Failed to validate {} with StringMaxLength",
|
||||
case
|
||||
);
|
||||
|
@ -350,7 +350,7 @@ pub async fn test_input_validator_string_email() {
|
|||
.into_result()
|
||||
.expect(&error_msg[..])
|
||||
.data,
|
||||
serde_json::json!({"fieldParameter": true}),
|
||||
value!({"fieldParameter": true}),
|
||||
"Failed to validate {} with Email",
|
||||
case
|
||||
);
|
||||
|
@ -362,7 +362,7 @@ pub async fn test_input_validator_string_email() {
|
|||
.into_result()
|
||||
.expect(&error_msg[..])
|
||||
.data,
|
||||
serde_json::json!({"inputObject": true}),
|
||||
value!({"inputObject": true}),
|
||||
"Failed to validate {} with Email",
|
||||
case
|
||||
);
|
||||
|
@ -546,7 +546,7 @@ pub async fn test_input_validator_string_mac() {
|
|||
.into_result()
|
||||
.expect(&error_msg[..])
|
||||
.data,
|
||||
serde_json::json!({"fieldParameter": true}),
|
||||
value!({"fieldParameter": true}),
|
||||
"Failed to validate {} with MAC",
|
||||
mac
|
||||
);
|
||||
|
@ -558,7 +558,7 @@ pub async fn test_input_validator_string_mac() {
|
|||
.into_result()
|
||||
.expect(&error_msg[..])
|
||||
.data,
|
||||
serde_json::json!({"inputObject": true}),
|
||||
value!({"inputObject": true}),
|
||||
"Failed to validate {} with MAC",
|
||||
mac
|
||||
);
|
||||
|
@ -605,7 +605,7 @@ pub async fn test_input_validator_string_mac() {
|
|||
.into_result()
|
||||
.expect(&error_msg[..])
|
||||
.data,
|
||||
serde_json::json!({"fieldParameter": true}),
|
||||
value!({"fieldParameter": true}),
|
||||
"Failed to validate {} with MAC",
|
||||
mac
|
||||
);
|
||||
|
@ -617,7 +617,7 @@ pub async fn test_input_validator_string_mac() {
|
|||
.into_result()
|
||||
.expect(&error_msg[..])
|
||||
.data,
|
||||
serde_json::json!({"inputObject": true}),
|
||||
value!({"inputObject": true}),
|
||||
"Failed to validate {} with MAC",
|
||||
mac
|
||||
);
|
||||
|
@ -742,7 +742,7 @@ pub async fn test_input_validator_int_range() {
|
|||
.into_result()
|
||||
.expect(&error_msg[..])
|
||||
.data,
|
||||
serde_json::json!({"fieldParameter": true}),
|
||||
value!({"fieldParameter": true}),
|
||||
"Failed to validate {} with IntRange",
|
||||
case
|
||||
);
|
||||
|
@ -754,7 +754,7 @@ pub async fn test_input_validator_int_range() {
|
|||
.into_result()
|
||||
.expect(&error_msg[..])
|
||||
.data,
|
||||
serde_json::json!({"inputObject": true}),
|
||||
value!({"inputObject": true}),
|
||||
"Failed to validate {} with IntRange",
|
||||
case
|
||||
);
|
||||
|
@ -847,7 +847,7 @@ pub async fn test_input_validator_int_less_than() {
|
|||
.into_result()
|
||||
.expect(&error_msg[..])
|
||||
.data,
|
||||
serde_json::json!({"fieldParameter": true}),
|
||||
value!({"fieldParameter": true}),
|
||||
"Failed to validate {} with IntLessThan",
|
||||
case
|
||||
);
|
||||
|
@ -859,7 +859,7 @@ pub async fn test_input_validator_int_less_than() {
|
|||
.into_result()
|
||||
.expect(&error_msg[..])
|
||||
.data,
|
||||
serde_json::json!({"inputObject": true}),
|
||||
value!({"inputObject": true}),
|
||||
"Failed to validate {} with IntLessThan",
|
||||
case
|
||||
);
|
||||
|
@ -954,7 +954,7 @@ pub async fn test_input_validator_int_greater_than() {
|
|||
.into_result()
|
||||
.expect(&error_msg[..])
|
||||
.data,
|
||||
serde_json::json!({"fieldParameter": true}),
|
||||
value!({"fieldParameter": true}),
|
||||
"Failed to validate {} with IntGreaterThan",
|
||||
case
|
||||
);
|
||||
|
@ -966,7 +966,7 @@ pub async fn test_input_validator_int_greater_than() {
|
|||
.into_result()
|
||||
.expect(&error_msg[..])
|
||||
.data,
|
||||
serde_json::json!({"inputObject": true}),
|
||||
value!({"inputObject": true}),
|
||||
"Failed to validate {} with IntGreaterThan",
|
||||
case
|
||||
);
|
||||
|
@ -1054,7 +1054,7 @@ pub async fn test_input_validator_int_nonzero() {
|
|||
.into_result()
|
||||
.expect(&error_msg[..])
|
||||
.data,
|
||||
serde_json::json!({"fieldParameter": true}),
|
||||
value!({"fieldParameter": true}),
|
||||
"Failed to validate {} with IntNonZero",
|
||||
case
|
||||
);
|
||||
|
@ -1066,7 +1066,7 @@ pub async fn test_input_validator_int_nonzero() {
|
|||
.into_result()
|
||||
.expect(&error_msg[..])
|
||||
.data,
|
||||
serde_json::json!({"inputObject": true}),
|
||||
value!({"inputObject": true}),
|
||||
"Failed to validate {} with IntNonZero",
|
||||
case
|
||||
);
|
||||
|
@ -1158,7 +1158,7 @@ pub async fn test_input_validator_int_equal() {
|
|||
.into_result()
|
||||
.expect(&error_msg[..])
|
||||
.data,
|
||||
serde_json::json!({"fieldParameter": true}),
|
||||
value!({"fieldParameter": true}),
|
||||
"Failed to validate {} with IntEqual",
|
||||
case
|
||||
);
|
||||
|
@ -1170,7 +1170,7 @@ pub async fn test_input_validator_int_equal() {
|
|||
.into_result()
|
||||
.expect(&error_msg[..])
|
||||
.data,
|
||||
serde_json::json!({"inputObject": true}),
|
||||
value!({"inputObject": true}),
|
||||
"Failed to validate {} with IntEqual",
|
||||
case
|
||||
);
|
||||
|
@ -1274,7 +1274,7 @@ pub async fn test_input_validator_list_max_length() {
|
|||
.into_result()
|
||||
.expect(&error_msg[..])
|
||||
.data,
|
||||
serde_json::json!({"fieldParameter": true}),
|
||||
value!({"fieldParameter": true}),
|
||||
"Failed to validate {:?} with ListMaxLength",
|
||||
case
|
||||
);
|
||||
|
@ -1286,7 +1286,7 @@ pub async fn test_input_validator_list_max_length() {
|
|||
.into_result()
|
||||
.expect(&error_msg[..])
|
||||
.data,
|
||||
serde_json::json!({"inputObject": true}),
|
||||
value!({"inputObject": true}),
|
||||
"Failed to validate {:?} with ListMaxLength",
|
||||
case
|
||||
);
|
||||
|
@ -1390,7 +1390,7 @@ pub async fn test_input_validator_list_min_length() {
|
|||
.into_result()
|
||||
.expect(&error_msg[..])
|
||||
.data,
|
||||
serde_json::json!({"fieldParameter": true}),
|
||||
value!({"fieldParameter": true}),
|
||||
"Failed to validate {:?} with ListMinLength",
|
||||
case
|
||||
);
|
||||
|
@ -1402,7 +1402,7 @@ pub async fn test_input_validator_list_min_length() {
|
|||
.into_result()
|
||||
.expect(&error_msg[..])
|
||||
.data,
|
||||
serde_json::json!({"inputObject": true}),
|
||||
value!({"inputObject": true}),
|
||||
"Failed to validate {:?} with ListMinLength",
|
||||
case
|
||||
);
|
||||
|
@ -1514,7 +1514,7 @@ pub async fn test_input_validator_operator_or() {
|
|||
.into_result()
|
||||
.expect(&error_msg[..])
|
||||
.data,
|
||||
serde_json::json!({"fieldParameter": true}),
|
||||
value!({"fieldParameter": true}),
|
||||
"Failed to validate {:?} with OR operator",
|
||||
case
|
||||
);
|
||||
|
@ -1526,7 +1526,7 @@ pub async fn test_input_validator_operator_or() {
|
|||
.into_result()
|
||||
.expect(&error_msg[..])
|
||||
.data,
|
||||
serde_json::json!({"inputObject": true}),
|
||||
value!({"inputObject": true}),
|
||||
"Failed to validate {:?} with OR operator",
|
||||
case
|
||||
);
|
||||
|
@ -1631,7 +1631,7 @@ pub async fn test_input_validator_operator_and() {
|
|||
.into_result()
|
||||
.expect(&error_msg[..])
|
||||
.data,
|
||||
serde_json::json!({"fieldParameter": true}),
|
||||
value!({"fieldParameter": true}),
|
||||
"Failed to validate {:?} with AND operator",
|
||||
case
|
||||
);
|
||||
|
@ -1643,7 +1643,7 @@ pub async fn test_input_validator_operator_and() {
|
|||
.into_result()
|
||||
.expect(&error_msg[..])
|
||||
.data,
|
||||
serde_json::json!({"inputObject": true}),
|
||||
value!({"inputObject": true}),
|
||||
"Failed to validate {:?} with AND operator",
|
||||
case
|
||||
);
|
||||
|
@ -1753,7 +1753,7 @@ pub async fn test_input_validator_variable() {
|
|||
.into_result()
|
||||
.expect(&error_msg[..])
|
||||
.data,
|
||||
serde_json::json!({"fieldParameter": true}),
|
||||
value!({"fieldParameter": true}),
|
||||
"Failed to validate {} with StringMinLength",
|
||||
case
|
||||
);
|
||||
|
@ -1765,7 +1765,7 @@ pub async fn test_input_validator_variable() {
|
|||
.into_result()
|
||||
.expect(&error_msg[..])
|
||||
.data,
|
||||
serde_json::json!({"inputObject": true}),
|
||||
value!({"inputObject": true}),
|
||||
"Failed to validate {} with StringMinLength",
|
||||
case
|
||||
);
|
||||
|
|
|
@ -37,7 +37,7 @@ pub async fn test_interface_simple_object() {
|
|||
let schema = Schema::new(Query, EmptyMutation, EmptySubscription);
|
||||
assert_eq!(
|
||||
schema.execute(query).await.into_result().unwrap().data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"node": {
|
||||
"id": 33,
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ pub async fn test_interface_simple_object2() {
|
|||
let schema = Schema::new(Query, EmptyMutation, EmptySubscription);
|
||||
assert_eq!(
|
||||
schema.execute(query).await.into_result().unwrap().data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"node": {
|
||||
"id": 33,
|
||||
}
|
||||
|
@ -148,7 +148,7 @@ pub async fn test_multiple_interfaces() {
|
|||
}"#;
|
||||
assert_eq!(
|
||||
schema.execute(query).await.into_result().unwrap().data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"myObj": {
|
||||
"valueA": 1,
|
||||
"valueB": 2,
|
||||
|
@ -226,7 +226,7 @@ pub async fn test_multiple_objects_in_multiple_interfaces() {
|
|||
}"#;
|
||||
assert_eq!(
|
||||
schema.execute(query).await.into_result().unwrap().data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"myObj": [{
|
||||
"valueA": 1,
|
||||
"valueB": 2,
|
||||
|
@ -274,7 +274,7 @@ pub async fn test_interface_field_result() {
|
|||
let schema = Schema::new(Query, EmptyMutation, EmptySubscription);
|
||||
assert_eq!(
|
||||
schema.execute(query).await.into_result().unwrap().data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"node": {
|
||||
"value": 10,
|
||||
}
|
||||
|
@ -324,7 +324,7 @@ pub async fn test_interface_field_method() {
|
|||
let schema = Schema::new(Query, EmptyMutation, EmptySubscription);
|
||||
assert_eq!(
|
||||
schema.execute(query).await.into_result().unwrap().data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"test": {
|
||||
"created_at": 1,
|
||||
}
|
||||
|
|
|
@ -195,7 +195,7 @@ impl Subscription {
|
|||
// }
|
||||
// "#;
|
||||
|
||||
// let res_json = serde_json::json!({
|
||||
// let res_json = value!({
|
||||
// "__schema": {
|
||||
// }
|
||||
// });
|
||||
|
@ -225,7 +225,7 @@ impl Subscription {
|
|||
// }
|
||||
// "#;
|
||||
//
|
||||
// let res_json = serde_json::json!({
|
||||
// let res_json = value!({
|
||||
// "__type": {
|
||||
// "name": "SimpleObject",
|
||||
// "description": "Is SimpleObject",
|
||||
|
@ -299,7 +299,7 @@ pub async fn test_introspection_deprecation() {
|
|||
// SimpleObject with deprecated inclusive
|
||||
let mut query = get_object_query("SimpleObject", "true");
|
||||
|
||||
let mut res_json = serde_json::json!({
|
||||
let mut res_json = value!({
|
||||
"__type": {
|
||||
"fields": [
|
||||
{
|
||||
|
@ -363,7 +363,7 @@ pub async fn test_introspection_deprecation() {
|
|||
// SimpleObject with deprecated fields exclusive
|
||||
query = get_object_query("SimpleObject", "false");
|
||||
|
||||
res_json = serde_json::json!({
|
||||
res_json = value!({
|
||||
"__type": {
|
||||
"fields": [
|
||||
{
|
||||
|
@ -422,7 +422,7 @@ pub async fn test_introspection_deprecation() {
|
|||
// Object with only one deprecated field inclusive
|
||||
query = get_object_query("Square", "true");
|
||||
|
||||
res_json = serde_json::json!({
|
||||
res_json = value!({
|
||||
"__type": {
|
||||
"fields": [
|
||||
{
|
||||
|
@ -441,7 +441,7 @@ pub async fn test_introspection_deprecation() {
|
|||
// Object with only one deprecated field exclusive
|
||||
query = get_object_query("Square", "false");
|
||||
|
||||
res_json = serde_json::json!({
|
||||
res_json = value!({
|
||||
"__type": {
|
||||
"fields": []
|
||||
}
|
||||
|
@ -471,7 +471,7 @@ pub async fn test_introspection_deprecation() {
|
|||
// Enum with deprecated value inclusive
|
||||
query = get_enum_query("TestEnum", "true");
|
||||
|
||||
res_json = serde_json::json!({
|
||||
res_json = value!({
|
||||
"__type": {
|
||||
"enumValues": [
|
||||
{
|
||||
|
@ -495,7 +495,7 @@ pub async fn test_introspection_deprecation() {
|
|||
// Enum with deprecated value exclusive
|
||||
query = get_enum_query("TestEnum", "false");
|
||||
|
||||
res_json = serde_json::json!({
|
||||
res_json = value!({
|
||||
"__type": {
|
||||
"enumValues": [
|
||||
{
|
||||
|
@ -531,7 +531,7 @@ pub async fn test_introspection_type_kind() {
|
|||
// Test simple object
|
||||
let mut query = get_type_kind_query("SimpleObject");
|
||||
|
||||
let mut res_json = serde_json::json!({
|
||||
let mut res_json = value!({
|
||||
"__type": {
|
||||
"name": "SimpleObject",
|
||||
"kind": "OBJECT"
|
||||
|
@ -545,7 +545,7 @@ pub async fn test_introspection_type_kind() {
|
|||
// Test object
|
||||
query = get_type_kind_query("Square");
|
||||
|
||||
res_json = serde_json::json!({
|
||||
res_json = value!({
|
||||
"__type": {
|
||||
"name": "Square",
|
||||
"kind": "OBJECT"
|
||||
|
@ -559,7 +559,7 @@ pub async fn test_introspection_type_kind() {
|
|||
// Test enum
|
||||
query = get_type_kind_query("TestEnum");
|
||||
|
||||
res_json = serde_json::json!({
|
||||
res_json = value!({
|
||||
"__type": {
|
||||
"name": "TestEnum",
|
||||
"kind": "ENUM"
|
||||
|
@ -573,7 +573,7 @@ pub async fn test_introspection_type_kind() {
|
|||
// Test union
|
||||
query = get_type_kind_query("TestUnion");
|
||||
|
||||
res_json = serde_json::json!({
|
||||
res_json = value!({
|
||||
"__type": {
|
||||
"name": "TestUnion",
|
||||
"kind": "UNION"
|
||||
|
@ -587,7 +587,7 @@ pub async fn test_introspection_type_kind() {
|
|||
// Test scalar
|
||||
query = get_type_kind_query("ID");
|
||||
|
||||
res_json = serde_json::json!({
|
||||
res_json = value!({
|
||||
"__type": {
|
||||
"name": "ID",
|
||||
"kind": "SCALAR"
|
||||
|
@ -615,7 +615,7 @@ pub async fn test_introspection_type_kind() {
|
|||
// Test list
|
||||
query = get_field_kind_query("SimpleList");
|
||||
|
||||
res_json = serde_json::json!({
|
||||
res_json = value!({
|
||||
"__type": {
|
||||
"fields": [
|
||||
{
|
||||
|
@ -640,7 +640,7 @@ pub async fn test_introspection_type_kind() {
|
|||
// Test NON_NULL
|
||||
query = get_field_kind_query("SimpleOption");
|
||||
|
||||
res_json = serde_json::json!({
|
||||
res_json = value!({
|
||||
"__type": {
|
||||
"fields": [
|
||||
{
|
||||
|
@ -685,7 +685,7 @@ pub async fn test_introspection_scalar() {
|
|||
}
|
||||
"#;
|
||||
|
||||
let res_json = serde_json::json!({
|
||||
let res_json = value!({
|
||||
"__type": {
|
||||
"kind": "SCALAR",
|
||||
"name": "TestScalar",
|
||||
|
@ -713,7 +713,7 @@ pub async fn test_introspection_union() {
|
|||
}
|
||||
"#;
|
||||
|
||||
let res_json = serde_json::json!({
|
||||
let res_json = value!({
|
||||
"__type": {
|
||||
"kind": "UNION",
|
||||
"name": "TestUnion",
|
||||
|
@ -751,7 +751,7 @@ pub async fn test_introspection_interface() {
|
|||
}
|
||||
"#;
|
||||
|
||||
let mut res_json = serde_json::json!({
|
||||
let mut res_json = value!({
|
||||
"__type": {
|
||||
"kind": "INTERFACE",
|
||||
"name": "TestInterface",
|
||||
|
@ -789,7 +789,7 @@ pub async fn test_introspection_interface() {
|
|||
}
|
||||
"#;
|
||||
|
||||
res_json = serde_json::json!({
|
||||
res_json = value!({
|
||||
"__type": {
|
||||
"kind": "OBJECT",
|
||||
"name": "Circle",
|
||||
|
@ -832,7 +832,7 @@ pub async fn test_introspection_enum() {
|
|||
}
|
||||
"#;
|
||||
|
||||
let res_json = serde_json::json!({
|
||||
let res_json = value!({
|
||||
"__type": {
|
||||
"kind": "ENUM",
|
||||
"name": "TestEnum",
|
||||
|
@ -876,7 +876,7 @@ pub async fn test_introspection_input_object() {
|
|||
}
|
||||
"#;
|
||||
|
||||
let res_json = serde_json::json!({
|
||||
let res_json = value!({
|
||||
"__type": {
|
||||
"kind": "INPUT_OBJECT",
|
||||
"name": "SimpleInput",
|
||||
|
@ -914,7 +914,7 @@ pub async fn test_introspection_mutation() {
|
|||
}
|
||||
"#;
|
||||
|
||||
let res_json = serde_json::json!({
|
||||
let res_json = value!({
|
||||
"__type": {
|
||||
"name": "Mutation",
|
||||
"kind": "OBJECT",
|
||||
|
@ -962,7 +962,7 @@ pub async fn test_introspection_subscription() {
|
|||
}
|
||||
"#;
|
||||
|
||||
let res_json = serde_json::json!({
|
||||
let res_json = value!({
|
||||
"__type": {
|
||||
"name": "Subscription",
|
||||
"kind": "OBJECT",
|
||||
|
@ -1017,7 +1017,7 @@ pub async fn test_introspection_subscription() {
|
|||
// }
|
||||
// "#;
|
||||
//
|
||||
// let res_json = serde_json::json!({
|
||||
// let res_json = value!({
|
||||
// "__type": {
|
||||
// "kind": "OBJECT",
|
||||
// "name": "SimpleObject",
|
||||
|
|
|
@ -46,7 +46,7 @@ pub async fn test_json_scalar() {
|
|||
let query = r#"{ data dataOutput dataOutputClone }"#;
|
||||
assert_eq!(
|
||||
schema.execute(query).await.data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"data": { "a": 10, "b": 20},
|
||||
"dataOutput": { "a": 10, "b": 20},
|
||||
"dataOutputClone": { "a": 10, "b": 20},
|
||||
|
|
|
@ -103,7 +103,7 @@ pub async fn test_list_type() {
|
|||
|
||||
assert_eq!(
|
||||
res,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"valueVec": vec![1, 2, 3, 4, 5],
|
||||
"valueSlice": vec![1, 2, 3, 4, 5],
|
||||
"valueLinkedList": vec![1, 2, 3, 4, 5],
|
||||
|
|
|
@ -45,7 +45,7 @@ pub async fn test_maybe_undefined_type() {
|
|||
"#;
|
||||
assert_eq!(
|
||||
schema.execute(query).await.data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"v1": 99,
|
||||
"v2": 1,
|
||||
"v3": 2,
|
||||
|
|
|
@ -45,7 +45,7 @@ pub async fn test_merged_object() {
|
|||
let query = "{ obj { a b c } }";
|
||||
assert_eq!(
|
||||
schema.execute(query).await.into_result().unwrap().data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"obj": {
|
||||
"a": 10,
|
||||
"b": 20,
|
||||
|
@ -73,7 +73,7 @@ pub async fn test_merged_object_macro() {
|
|||
let query = "{ obj { a b c } }";
|
||||
assert_eq!(
|
||||
schema.execute(query).await.into_result().unwrap().data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"obj": {
|
||||
"a": 10,
|
||||
"b": 20,
|
||||
|
@ -101,7 +101,7 @@ pub async fn test_merged_object_derive() {
|
|||
let query = "{ obj { a b c } }";
|
||||
assert_eq!(
|
||||
schema.execute(query).await.into_result().unwrap().data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"obj": {
|
||||
"a": 10,
|
||||
"b": 20,
|
||||
|
@ -150,7 +150,7 @@ pub async fn test_merged_object_default() {
|
|||
let query = "{ a b }";
|
||||
assert_eq!(
|
||||
schema.execute(query).await.into_result().unwrap().data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"a": 10,
|
||||
"b": 20,
|
||||
})
|
||||
|
@ -196,7 +196,7 @@ pub async fn test_merged_subscription() {
|
|||
.boxed();
|
||||
for i in 0i32..10 {
|
||||
assert_eq!(
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"events1": i,
|
||||
}),
|
||||
stream.next().await.unwrap()
|
||||
|
@ -212,7 +212,7 @@ pub async fn test_merged_subscription() {
|
|||
.boxed();
|
||||
for i in 10i32..20 {
|
||||
assert_eq!(
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"events2": i,
|
||||
}),
|
||||
stream.next().await.unwrap()
|
||||
|
|
|
@ -16,7 +16,7 @@ pub async fn test_mut_args() {
|
|||
let schema = Schema::build(Query, EmptyMutation, EmptySubscription).finish();
|
||||
assert_eq!(
|
||||
schema.execute("{ test(a: 10, b: \"abc\") }").await.data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"test": "11abca"
|
||||
})
|
||||
);
|
||||
|
|
|
@ -66,7 +66,7 @@ pub async fn test_mutation_fragment() {
|
|||
.await;
|
||||
assert_eq!(
|
||||
resp.data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"actionInUnnamedFragment": true,
|
||||
"actionInNamedFragment": true,
|
||||
})
|
||||
|
|
|
@ -60,7 +60,7 @@ pub async fn test_optional_type() {
|
|||
.to_owned();
|
||||
assert_eq!(
|
||||
schema.execute(&query).await.data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"value1": 10,
|
||||
"value1Ref": 10,
|
||||
"value2": null,
|
||||
|
|
|
@ -54,7 +54,7 @@ pub async fn test_input_value_custom_error() {
|
|||
}"#;
|
||||
assert_eq!(
|
||||
schema.execute(query).await.into_result().unwrap().data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"type": 99,
|
||||
"obj": { "i32": 88 },
|
||||
"enumValue": "TYPE",
|
||||
|
@ -67,10 +67,7 @@ pub async fn test_input_value_custom_error() {
|
|||
.map_ok(|resp| resp.data)
|
||||
.boxed();
|
||||
for i in 0..10 {
|
||||
assert_eq!(
|
||||
serde_json::json!({ "type": i }),
|
||||
stream.next().await.unwrap().unwrap()
|
||||
);
|
||||
assert_eq!(value!({ "type": i }), stream.next().await.unwrap().unwrap());
|
||||
}
|
||||
assert!(stream.next().await.is_none());
|
||||
}
|
||||
|
|
|
@ -35,10 +35,7 @@ pub async fn test_subscription() {
|
|||
.map(|resp| resp.into_result().unwrap().data)
|
||||
.boxed();
|
||||
for i in 10..20 {
|
||||
assert_eq!(
|
||||
serde_json::json!({ "values": i }),
|
||||
stream.next().await.unwrap()
|
||||
);
|
||||
assert_eq!(value!({ "values": i }), stream.next().await.unwrap());
|
||||
}
|
||||
assert!(stream.next().await.is_none());
|
||||
}
|
||||
|
@ -50,7 +47,7 @@ pub async fn test_subscription() {
|
|||
.boxed();
|
||||
for i in 10..20 {
|
||||
assert_eq!(
|
||||
serde_json::json!({ "events": {"a": i, "b": i * 10} }),
|
||||
value!({ "events": {"a": i, "b": i * 10} }),
|
||||
stream.next().await.unwrap()
|
||||
);
|
||||
}
|
||||
|
@ -95,12 +92,9 @@ pub async fn test_subscription_with_ctx_data() {
|
|||
.execute_stream(Request::new("subscription { values objects { value } }").data(100i32))
|
||||
.map(|resp| resp.data)
|
||||
.boxed();
|
||||
assert_eq!(value!({ "values": 100 }), stream.next().await.unwrap());
|
||||
assert_eq!(
|
||||
serde_json::json!({ "values": 100 }),
|
||||
stream.next().await.unwrap()
|
||||
);
|
||||
assert_eq!(
|
||||
serde_json::json!({ "objects": { "value": 100 } }),
|
||||
value!({ "objects": { "value": 100 } }),
|
||||
stream.next().await.unwrap()
|
||||
);
|
||||
assert!(stream.next().await.is_none());
|
||||
|
@ -137,10 +131,7 @@ pub async fn test_subscription_with_token() {
|
|||
)
|
||||
.map(|resp| resp.into_result().unwrap().data)
|
||||
.boxed();
|
||||
assert_eq!(
|
||||
serde_json::json!({ "values": 100 }),
|
||||
stream.next().await.unwrap()
|
||||
);
|
||||
assert_eq!(value!({ "values": 100 }), stream.next().await.unwrap());
|
||||
assert!(stream.next().await.is_none());
|
||||
}
|
||||
|
||||
|
@ -197,7 +188,7 @@ pub async fn test_subscription_inline_fragment() {
|
|||
.boxed();
|
||||
for i in 10..20 {
|
||||
assert_eq!(
|
||||
serde_json::json!({ "events": {"a": i, "b": i * 10} }),
|
||||
value!({ "events": {"a": i, "b": i * 10} }),
|
||||
stream.next().await.unwrap()
|
||||
);
|
||||
}
|
||||
|
@ -252,7 +243,7 @@ pub async fn test_subscription_fragment() {
|
|||
.boxed();
|
||||
for i in 10i32..20 {
|
||||
assert_eq!(
|
||||
serde_json::json!({ "events": {"a": i, "b": i * 10} }),
|
||||
value!({ "events": {"a": i, "b": i * 10} }),
|
||||
stream.next().await.unwrap()
|
||||
);
|
||||
}
|
||||
|
@ -308,7 +299,7 @@ pub async fn test_subscription_fragment2() {
|
|||
.boxed();
|
||||
for i in 10..20 {
|
||||
assert_eq!(
|
||||
serde_json::json!({ "events": {"a": i, "b": i * 10} }),
|
||||
value!({ "events": {"a": i, "b": i * 10} }),
|
||||
stream.next().await.unwrap()
|
||||
);
|
||||
}
|
||||
|
@ -354,7 +345,7 @@ pub async fn test_subscription_error() {
|
|||
.boxed();
|
||||
for i in 0i32..5 {
|
||||
assert_eq!(
|
||||
serde_json::json!({ "events": { "value": i } }),
|
||||
value!({ "events": { "value": i } }),
|
||||
stream.next().await.unwrap().unwrap()
|
||||
);
|
||||
}
|
||||
|
@ -405,7 +396,7 @@ pub async fn test_subscription_fieldresult() {
|
|||
.boxed();
|
||||
for i in 0i32..5 {
|
||||
assert_eq!(
|
||||
serde_json::json!({ "values": i }),
|
||||
value!({ "values": i }),
|
||||
stream.next().await.unwrap().unwrap()
|
||||
);
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ pub async fn test_subscription_ws_transport() {
|
|||
let mut stream = http::WebSocket::new(schema, rx);
|
||||
|
||||
tx.send(
|
||||
serde_json::to_string(&serde_json::json!({
|
||||
serde_json::to_string(&value!({
|
||||
"type": "connection_init",
|
||||
}))
|
||||
.unwrap(),
|
||||
|
@ -39,7 +39,7 @@ pub async fn test_subscription_ws_transport() {
|
|||
);
|
||||
|
||||
tx.send(
|
||||
serde_json::to_string(&serde_json::json!({
|
||||
serde_json::to_string(&value!({
|
||||
"type": "start",
|
||||
"id": "1",
|
||||
"payload": {
|
||||
|
@ -111,7 +111,7 @@ pub async fn test_subscription_ws_transport_with_token() {
|
|||
);
|
||||
|
||||
tx.send(
|
||||
serde_json::to_string(&serde_json::json!({
|
||||
serde_json::to_string(&value!({
|
||||
"type": "connection_init",
|
||||
"payload": { "token": "123456" }
|
||||
}))
|
||||
|
@ -121,14 +121,14 @@ pub async fn test_subscription_ws_transport_with_token() {
|
|||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
Some(serde_json::json!({
|
||||
Some(value!({
|
||||
"type": "connection_ack",
|
||||
})),
|
||||
serde_json::from_str(&stream.next().await.unwrap()).unwrap()
|
||||
);
|
||||
|
||||
tx.send(
|
||||
serde_json::to_string(&serde_json::json!({
|
||||
serde_json::to_string(&value!({
|
||||
"type": "start",
|
||||
"id": "1",
|
||||
"payload": {
|
||||
|
@ -142,7 +142,7 @@ pub async fn test_subscription_ws_transport_with_token() {
|
|||
|
||||
for i in 0..10 {
|
||||
assert_eq!(
|
||||
Some(serde_json::json!({
|
||||
Some(value!({
|
||||
"type": "data",
|
||||
"id": "1",
|
||||
"payload": { "data": { "values": i } },
|
||||
|
@ -152,7 +152,7 @@ pub async fn test_subscription_ws_transport_with_token() {
|
|||
}
|
||||
|
||||
assert_eq!(
|
||||
Some(serde_json::json!({
|
||||
Some(value!({
|
||||
"type": "complete",
|
||||
"id": "1",
|
||||
})),
|
||||
|
@ -196,7 +196,7 @@ pub async fn test_subscription_ws_transport_error() {
|
|||
let mut stream = http::WebSocket::new(schema, rx);
|
||||
|
||||
tx.send(
|
||||
serde_json::to_string(&serde_json::json!({
|
||||
serde_json::to_string(&value!({
|
||||
"type": "connection_init"
|
||||
}))
|
||||
.unwrap(),
|
||||
|
@ -205,14 +205,14 @@ pub async fn test_subscription_ws_transport_error() {
|
|||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
Some(serde_json::json!({
|
||||
Some(value!({
|
||||
"type": "connection_ack",
|
||||
})),
|
||||
serde_json::from_str(&stream.next().await.unwrap()).unwrap()
|
||||
);
|
||||
|
||||
tx.send(
|
||||
serde_json::to_string(&serde_json::json!({
|
||||
serde_json::to_string(&value!({
|
||||
"type": "start",
|
||||
"id": "1",
|
||||
"payload": {
|
||||
|
@ -226,7 +226,7 @@ pub async fn test_subscription_ws_transport_error() {
|
|||
|
||||
for i in 0i32..5 {
|
||||
assert_eq!(
|
||||
Some(serde_json::json!({
|
||||
Some(value!({
|
||||
"type": "data",
|
||||
"id": "1",
|
||||
"payload": { "data": { "events": { "value": i } } },
|
||||
|
@ -236,7 +236,7 @@ pub async fn test_subscription_ws_transport_error() {
|
|||
}
|
||||
|
||||
assert_eq!(
|
||||
Some(serde_json::json!({
|
||||
Some(value!({
|
||||
"type": "data",
|
||||
"id": "1",
|
||||
"payload": {
|
||||
|
@ -268,7 +268,7 @@ pub async fn test_query_over_websocket() {
|
|||
let mut stream = http::WebSocket::new(schema, rx);
|
||||
|
||||
tx.send(
|
||||
serde_json::to_string(&serde_json::json!({
|
||||
serde_json::to_string(&value!({
|
||||
"type": "connection_init",
|
||||
}))
|
||||
.unwrap(),
|
||||
|
@ -277,14 +277,14 @@ pub async fn test_query_over_websocket() {
|
|||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
Some(serde_json::json!({
|
||||
Some(value!({
|
||||
"type": "connection_ack",
|
||||
})),
|
||||
serde_json::from_str(&stream.next().await.unwrap()).unwrap()
|
||||
);
|
||||
|
||||
tx.send(
|
||||
serde_json::to_string(&serde_json::json!({
|
||||
serde_json::to_string(&value!({
|
||||
"type": "start",
|
||||
"id": "1",
|
||||
"payload": {
|
||||
|
@ -297,7 +297,7 @@ pub async fn test_query_over_websocket() {
|
|||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
Some(serde_json::json!({
|
||||
Some(value!({
|
||||
"type": "data",
|
||||
"id": "1",
|
||||
"payload": { "data": { "value": 999 } },
|
||||
|
@ -306,7 +306,7 @@ pub async fn test_query_over_websocket() {
|
|||
);
|
||||
|
||||
assert_eq!(
|
||||
Some(serde_json::json!({
|
||||
Some(value!({
|
||||
"type": "complete",
|
||||
"id": "1",
|
||||
})),
|
||||
|
|
|
@ -36,7 +36,7 @@ pub async fn test_union_simple_object() {
|
|||
let schema = Schema::new(Query, EmptyMutation, EmptySubscription);
|
||||
assert_eq!(
|
||||
schema.execute(query).await.into_result().unwrap().data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"node": {
|
||||
"id": 33,
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ pub async fn test_union_simple_object2() {
|
|||
let schema = Schema::new(Query, EmptyMutation, EmptySubscription);
|
||||
assert_eq!(
|
||||
schema.execute(query).await.into_result().unwrap().data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"node": {
|
||||
"id": 33,
|
||||
}
|
||||
|
@ -150,7 +150,7 @@ pub async fn test_multiple_unions() {
|
|||
}"#;
|
||||
assert_eq!(
|
||||
schema.execute(query).await.into_result().unwrap().data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"unionA": {
|
||||
"valueA": 1,
|
||||
"valueB": 2,
|
||||
|
@ -230,7 +230,7 @@ pub async fn test_multiple_objects_in_multiple_unions() {
|
|||
}"#;
|
||||
assert_eq!(
|
||||
schema.execute(query).await.into_result().unwrap().data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"myObj": [{
|
||||
"valueA": 1,
|
||||
"valueB": 2,
|
||||
|
@ -277,7 +277,7 @@ pub async fn test_union_field_result() {
|
|||
let schema = Schema::new(Query, EmptyMutation, EmptySubscription);
|
||||
assert_eq!(
|
||||
schema.execute(query).await.into_result().unwrap().data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"node": {
|
||||
"value": 10,
|
||||
}
|
||||
|
@ -345,7 +345,7 @@ pub async fn test_union_flatten() {
|
|||
}"#;
|
||||
assert_eq!(
|
||||
schema.execute(query).await.into_result().unwrap().data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"value1": {
|
||||
"value1": 99,
|
||||
},
|
||||
|
|
|
@ -25,14 +25,14 @@ pub async fn test_variables() {
|
|||
}
|
||||
"#,
|
||||
)
|
||||
.variables(Variables::from_json(serde_json::json!({
|
||||
.variables(Variables::from_value(value!({
|
||||
"intVal": 10,
|
||||
"intListVal": [1, 2, 3, 4, 5],
|
||||
})));
|
||||
|
||||
assert_eq!(
|
||||
schema.execute(query).await.data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"intVal": 10,
|
||||
"intListVal": [1, 2, 3, 4, 5],
|
||||
})
|
||||
|
@ -62,7 +62,7 @@ pub async fn test_variable_default_value() {
|
|||
)
|
||||
.await
|
||||
.data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"intVal": 10,
|
||||
})
|
||||
);
|
||||
|
@ -93,7 +93,7 @@ pub async fn test_variable_no_value() {
|
|||
.unwrap();
|
||||
assert_eq!(
|
||||
resp.data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"intVal": 10,
|
||||
})
|
||||
);
|
||||
|
@ -118,13 +118,13 @@ pub async fn test_variable_null() {
|
|||
}
|
||||
"#,
|
||||
)
|
||||
.variables(Variables::from_json(serde_json::json!({
|
||||
.variables(Variables::from_value(value!({
|
||||
"intVal": null,
|
||||
})));
|
||||
let resp = schema.execute(query).await;
|
||||
assert_eq!(
|
||||
resp.data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"intVal": 10,
|
||||
})
|
||||
);
|
||||
|
@ -168,15 +168,13 @@ pub async fn test_variable_in_input_object() {
|
|||
test(input: {value: $value })
|
||||
}"#;
|
||||
let resp = schema
|
||||
.execute(
|
||||
Request::new(query).variables(Variables::from_json(serde_json::json!({
|
||||
"value": 10,
|
||||
}))),
|
||||
)
|
||||
.execute(Request::new(query).variables(Variables::from_value(value!({
|
||||
"value": 10,
|
||||
}))))
|
||||
.await;
|
||||
assert_eq!(
|
||||
resp.data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"test": 10,
|
||||
})
|
||||
);
|
||||
|
@ -189,15 +187,13 @@ pub async fn test_variable_in_input_object() {
|
|||
test2(input: [{value: $value }, {value: $value }])
|
||||
}"#;
|
||||
let resp = schema
|
||||
.execute(
|
||||
Request::new(query).variables(Variables::from_json(serde_json::json!({
|
||||
"value": 3,
|
||||
}))),
|
||||
)
|
||||
.execute(Request::new(query).variables(Variables::from_value(value!({
|
||||
"value": 3,
|
||||
}))))
|
||||
.await;
|
||||
assert_eq!(
|
||||
resp.data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"test2": 6,
|
||||
})
|
||||
);
|
||||
|
@ -210,15 +206,13 @@ pub async fn test_variable_in_input_object() {
|
|||
test(input: {value: $value })
|
||||
}"#;
|
||||
let resp = schema
|
||||
.execute(
|
||||
Request::new(query).variables(Variables::from_json(serde_json::json!({
|
||||
"value": 10,
|
||||
}))),
|
||||
)
|
||||
.execute(Request::new(query).variables(Variables::from_value(value!({
|
||||
"value": 10,
|
||||
}))))
|
||||
.await;
|
||||
assert_eq!(
|
||||
resp.data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"test": 10,
|
||||
})
|
||||
);
|
||||
|
@ -257,7 +251,7 @@ pub async fn test_variables_enum() {
|
|||
}
|
||||
"#,
|
||||
)
|
||||
.variables(Variables::from_json(serde_json::json!({
|
||||
.variables(Variables::from_value(value!({
|
||||
"value1": "A",
|
||||
"value2": "B",
|
||||
"value3": "C",
|
||||
|
@ -265,7 +259,7 @@ pub async fn test_variables_enum() {
|
|||
|
||||
assert_eq!(
|
||||
schema.execute(query).await.into_result().unwrap().data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"a": 1,
|
||||
"b": 2,
|
||||
"c": 3,
|
||||
|
@ -292,13 +286,13 @@ pub async fn test_variables_json() {
|
|||
}
|
||||
"#,
|
||||
)
|
||||
.variables(Variables::from_json(serde_json::json!({
|
||||
.variables(Variables::from_value(value!({
|
||||
"value": { "a-b": 123 },
|
||||
})));
|
||||
|
||||
assert_eq!(
|
||||
schema.execute(query).await.into_result().unwrap().data,
|
||||
serde_json::json!({
|
||||
value!({
|
||||
"value": 123,
|
||||
})
|
||||
);
|
||||
|
|
|
@ -112,7 +112,7 @@ impl<'de> Deserialize<'de> for Name {
|
|||
/// serialize `Upload` will fail, and `Enum` and `Upload` cannot be deserialized.
|
||||
///
|
||||
/// [Reference](https://spec.graphql.org/June2018/#Value).
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[derive(Clone, Debug, Eq, Serialize, Deserialize)]
|
||||
#[serde(untagged)]
|
||||
pub enum ConstValue {
|
||||
/// `null`.
|
||||
|
@ -132,6 +132,43 @@ pub enum ConstValue {
|
|||
Object(BTreeMap<Name, ConstValue>),
|
||||
}
|
||||
|
||||
impl PartialEq for ConstValue {
|
||||
fn eq(&self, other: &ConstValue) -> bool {
|
||||
match (self, other) {
|
||||
(ConstValue::Null, ConstValue::Null) => true,
|
||||
(ConstValue::Number(a), ConstValue::Number(b)) => a == b,
|
||||
(ConstValue::Boolean(a), ConstValue::Boolean(b)) => a == b,
|
||||
(ConstValue::String(a), ConstValue::String(b)) => a == b,
|
||||
(ConstValue::Enum(a), ConstValue::String(b)) => a == b,
|
||||
(ConstValue::String(a), ConstValue::Enum(b)) => a == b,
|
||||
(ConstValue::Enum(a), ConstValue::Enum(b)) => a == b,
|
||||
(ConstValue::List(a), ConstValue::List(b)) => {
|
||||
if a.len() != b.len() {
|
||||
return false;
|
||||
}
|
||||
a.iter().zip(b.iter()).all(|(a, b)| a == b)
|
||||
}
|
||||
(ConstValue::Object(a), ConstValue::Object(b)) => {
|
||||
if a.len() != b.len() {
|
||||
return false;
|
||||
}
|
||||
for (a_key, a_value) in a.iter() {
|
||||
if let Some(b_value) = b.get(a_key.as_str()) {
|
||||
if b_value != a_value {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
true
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<()> for ConstValue {
|
||||
fn from((): ()) -> Self {
|
||||
ConstValue::Null
|
||||
|
@ -212,47 +249,6 @@ impl From<BTreeMap<Name, ConstValue>> for ConstValue {
|
|||
}
|
||||
}
|
||||
|
||||
impl PartialEq<serde_json::Value> for ConstValue {
|
||||
fn eq(&self, other: &serde_json::Value) -> bool {
|
||||
match (self, other) {
|
||||
(ConstValue::Null, serde_json::Value::Null) => true,
|
||||
(ConstValue::Number(a), serde_json::Value::Number(b)) => a == b,
|
||||
(ConstValue::String(a), serde_json::Value::String(b)) => a == b,
|
||||
(ConstValue::Boolean(a), serde_json::Value::Bool(b)) => a == b,
|
||||
(ConstValue::Enum(a), serde_json::Value::String(b)) => a == b,
|
||||
(ConstValue::List(a), serde_json::Value::Array(b)) => {
|
||||
if a.len() != b.len() {
|
||||
return false;
|
||||
}
|
||||
a.iter().zip(b.iter()).all(|(a, b)| a == b)
|
||||
}
|
||||
(ConstValue::Object(a), serde_json::Value::Object(b)) => {
|
||||
if a.len() != b.len() {
|
||||
return false;
|
||||
}
|
||||
for (a_key, a_value) in a.iter() {
|
||||
if let Some(b_value) = b.get(a_key.as_str()) {
|
||||
if b_value != a_value {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
true
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq<ConstValue> for serde_json::Value {
|
||||
fn eq(&self, other: &ConstValue) -> bool {
|
||||
other == self
|
||||
}
|
||||
}
|
||||
|
||||
impl ConstValue {
|
||||
/// Convert this `ConstValue` into a `Value`.
|
||||
#[must_use]
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#[macro_export]
|
||||
macro_rules! value {
|
||||
($($json:tt)+) => {
|
||||
value_internal!($($json)+)
|
||||
$crate::value_internal!($($json)+)
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -11,57 +11,57 @@ macro_rules! value {
|
|||
macro_rules! value_internal {
|
||||
// Done with trailing comma.
|
||||
(@array [$($elems:expr,)*]) => {
|
||||
value_internal_vec![$($elems,)*]
|
||||
$crate::value_internal_vec![$($elems,)*]
|
||||
};
|
||||
|
||||
// Done without trailing comma.
|
||||
(@array [$($elems:expr),*]) => {
|
||||
value_internal_vec![$($elems),*]
|
||||
$crate::value_internal_vec![$($elems),*]
|
||||
};
|
||||
|
||||
// Next element is `null`.
|
||||
(@array [$($elems:expr,)*] null $($rest:tt)*) => {
|
||||
value_internal!(@array [$($elems,)* value_internal!(null)] $($rest)*)
|
||||
$crate::value_internal!(@array [$($elems,)* $crate::value_internal!(null)] $($rest)*)
|
||||
};
|
||||
|
||||
// Next element is `true`.
|
||||
(@array [$($elems:expr,)*] true $($rest:tt)*) => {
|
||||
value_internal!(@array [$($elems,)* value_internal!(true)] $($rest)*)
|
||||
$crate::value_internal!(@array [$($elems,)* $crate::value_internal!(true)] $($rest)*)
|
||||
};
|
||||
|
||||
// Next element is `false`.
|
||||
(@array [$($elems:expr,)*] false $($rest:tt)*) => {
|
||||
value_internal!(@array [$($elems,)* value_internal!(false)] $($rest)*)
|
||||
$crate::value_internal!(@array [$($elems,)* $crate::value_internal!(false)] $($rest)*)
|
||||
};
|
||||
|
||||
// Next element is an array.
|
||||
(@array [$($elems:expr,)*] [$($array:tt)*] $($rest:tt)*) => {
|
||||
value_internal!(@array [$($elems,)* value_internal!([$($array)*])] $($rest)*)
|
||||
$crate::value_internal!(@array [$($elems,)* $crate::value_internal!([$($array)*])] $($rest)*)
|
||||
};
|
||||
|
||||
// Next element is a map.
|
||||
(@array [$($elems:expr,)*] {$($map:tt)*} $($rest:tt)*) => {
|
||||
value_internal!(@array [$($elems,)* value_internal!({$($map)*})] $($rest)*)
|
||||
$crate::value_internal!(@array [$($elems,)* $crate::value_internal!({$($map)*})] $($rest)*)
|
||||
};
|
||||
|
||||
// Next element is an expression followed by comma.
|
||||
(@array [$($elems:expr,)*] $next:expr, $($rest:tt)*) => {
|
||||
value_internal!(@array [$($elems,)* value_internal!($next),] $($rest)*)
|
||||
$crate::value_internal!(@array [$($elems,)* $crate::value_internal!($next),] $($rest)*)
|
||||
};
|
||||
|
||||
// Last element is an expression with no trailing comma.
|
||||
(@array [$($elems:expr,)*] $last:expr) => {
|
||||
value_internal!(@array [$($elems,)* value_internal!($last)])
|
||||
$crate::value_internal!(@array [$($elems,)* $crate::value_internal!($last)])
|
||||
};
|
||||
|
||||
// Comma after the most recent element.
|
||||
(@array [$($elems:expr),*] , $($rest:tt)*) => {
|
||||
value_internal!(@array [$($elems,)*] $($rest)*)
|
||||
$crate::value_internal!(@array [$($elems,)*] $($rest)*)
|
||||
};
|
||||
|
||||
// Unexpected token after most recent element.
|
||||
(@array [$($elems:expr),*] $unexpected:tt $($rest:tt)*) => {
|
||||
value_unexpected!($unexpected)
|
||||
$crate::value_unexpected!($unexpected)
|
||||
};
|
||||
|
||||
// Done.
|
||||
|
@ -70,12 +70,12 @@ macro_rules! value_internal {
|
|||
// Insert the current entry followed by trailing comma.
|
||||
(@object $object:ident [$($key:tt)+] ($value:expr) , $($rest:tt)*) => {
|
||||
let _ = $object.insert($crate::Name::new($($key)+), $value);
|
||||
value_internal!(@object $object () ($($rest)*) ($($rest)*));
|
||||
$crate::value_internal!(@object $object () ($($rest)*) ($($rest)*));
|
||||
};
|
||||
|
||||
// Current entry followed by unexpected token.
|
||||
(@object $object:ident [$($key:tt)+] ($value:expr) $unexpected:tt $($rest:tt)*) => {
|
||||
value_unexpected!($unexpected);
|
||||
$crate::value_unexpected!($unexpected);
|
||||
};
|
||||
|
||||
// Insert the last entry without trailing comma.
|
||||
|
@ -85,78 +85,78 @@ macro_rules! value_internal {
|
|||
|
||||
// Next value is `null`.
|
||||
(@object $object:ident ($($key:tt)+) (: null $($rest:tt)*) $copy:tt) => {
|
||||
value_internal!(@object $object [$($key)+] (value_internal!(null)) $($rest)*);
|
||||
$crate::value_internal!(@object $object [$($key)+] ($crate::value_internal!(null)) $($rest)*);
|
||||
};
|
||||
|
||||
// Next value is `true`.
|
||||
(@object $object:ident ($($key:tt)+) (: true $($rest:tt)*) $copy:tt) => {
|
||||
value_internal!(@object $object [$($key)+] (value_internal!(true)) $($rest)*);
|
||||
$crate::value_internal!(@object $object [$($key)+] ($crate::value_internal!(true)) $($rest)*);
|
||||
};
|
||||
|
||||
// Next value is `false`.
|
||||
(@object $object:ident ($($key:tt)+) (: false $($rest:tt)*) $copy:tt) => {
|
||||
value_internal!(@object $object [$($key)+] (value_internal!(false)) $($rest)*);
|
||||
$crate::value_internal!(@object $object [$($key)+] ($crate::value_internal!(false)) $($rest)*);
|
||||
};
|
||||
|
||||
// Next value is an array.
|
||||
(@object $object:ident ($($key:tt)+) (: [$($array:tt)*] $($rest:tt)*) $copy:tt) => {
|
||||
value_internal!(@object $object [$($key)+] (value_internal!([$($array)*])) $($rest)*);
|
||||
$crate::value_internal!(@object $object [$($key)+] ($crate::value_internal!([$($array)*])) $($rest)*);
|
||||
};
|
||||
|
||||
// Next value is a map.
|
||||
(@object $object:ident ($($key:tt)+) (: {$($map:tt)*} $($rest:tt)*) $copy:tt) => {
|
||||
value_internal!(@object $object [$($key)+] (value_internal!({$($map)*})) $($rest)*);
|
||||
$crate::value_internal!(@object $object [$($key)+] ($crate::value_internal!({$($map)*})) $($rest)*);
|
||||
};
|
||||
|
||||
// Next value is an expression followed by comma.
|
||||
(@object $object:ident ($($key:tt)+) (: $value:expr , $($rest:tt)*) $copy:tt) => {
|
||||
value_internal!(@object $object [$($key)+] (value_internal!($value)) , $($rest)*);
|
||||
$crate::value_internal!(@object $object [$($key)+] ($crate::value_internal!($value)) , $($rest)*);
|
||||
};
|
||||
|
||||
// Last value is an expression with no trailing comma.
|
||||
(@object $object:ident ($($key:tt)+) (: $value:expr) $copy:tt) => {
|
||||
value_internal!(@object $object [$($key)+] (value_internal!($value)));
|
||||
$crate::value_internal!(@object $object [$($key)+] ($crate::value_internal!($value)));
|
||||
};
|
||||
|
||||
// Missing value for last entry. Trigger a reasonable error message.
|
||||
(@object $object:ident ($($key:tt)+) (:) $copy:tt) => {
|
||||
// "unexpected end of macro invocation"
|
||||
value_internal!();
|
||||
$crate::value_internal!();
|
||||
};
|
||||
|
||||
// Missing colon and value for last entry. Trigger a reasonable error
|
||||
// message.
|
||||
(@object $object:ident ($($key:tt)+) () $copy:tt) => {
|
||||
// "unexpected end of macro invocation"
|
||||
value_internal!();
|
||||
$crate::value_internal!();
|
||||
};
|
||||
|
||||
// Misplaced colon. Trigger a reasonable error message.
|
||||
(@object $object:ident () (: $($rest:tt)*) ($colon:tt $($copy:tt)*)) => {
|
||||
// Takes no arguments so "no rules expected the token `:`".
|
||||
value_unexpected!($colon);
|
||||
$crate::value_unexpected!($colon);
|
||||
};
|
||||
|
||||
// Found a comma inside a key. Trigger a reasonable error message.
|
||||
(@object $object:ident ($($key:tt)*) (, $($rest:tt)*) ($comma:tt $($copy:tt)*)) => {
|
||||
// Takes no arguments so "no rules expected the token `,`".
|
||||
value_unexpected!($comma);
|
||||
$crate::value_unexpected!($comma);
|
||||
};
|
||||
|
||||
// Key is fully parenthesized. This avoids clippy double_parens false
|
||||
// positives because the parenthesization may be necessary here.
|
||||
(@object $object:ident () (($key:expr) : $($rest:tt)*) $copy:tt) => {
|
||||
value_internal!(@object $object ($key) (: $($rest)*) (: $($rest)*));
|
||||
$crate::value_internal!(@object $object ($key) (: $($rest)*) (: $($rest)*));
|
||||
};
|
||||
|
||||
// Refuse to absorb colon token into key expression.
|
||||
(@object $object:ident ($($key:tt)*) (: $($unexpected:tt)+) $copy:tt) => {
|
||||
value_expect_expr_comma!($($unexpected)+);
|
||||
$crate::value_expect_expr_comma!($($unexpected)+);
|
||||
};
|
||||
|
||||
// Munch a token into the current key.
|
||||
(@object $object:ident ($($key:tt)*) ($tt:tt $($rest:tt)*) $copy:tt) => {
|
||||
value_internal!(@object $object ($($key)* $tt) ($($rest)*) ($($rest)*));
|
||||
$crate::value_internal!(@object $object ($($key)* $tt) ($($rest)*) ($($rest)*));
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
@ -166,7 +166,7 @@ macro_rules! value_internal {
|
|||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
(null) => {
|
||||
$crate::Value::Null
|
||||
$crate::ConstValue::Null
|
||||
};
|
||||
|
||||
(true) => {
|
||||
|
@ -178,11 +178,11 @@ macro_rules! value_internal {
|
|||
};
|
||||
|
||||
([]) => {
|
||||
$crate::ConstValue::List(value_internal_vec![])
|
||||
$crate::ConstValue::List($crate::value_internal_vec![])
|
||||
};
|
||||
|
||||
([ $($tt:tt)+ ]) => {
|
||||
$crate::ConstValue::List(value_internal!(@array [] $($tt)+))
|
||||
$crate::ConstValue::List($crate::value_internal!(@array [] $($tt)+))
|
||||
};
|
||||
|
||||
({}) => {
|
||||
|
@ -192,7 +192,7 @@ macro_rules! value_internal {
|
|||
({ $($tt:tt)+ }) => {
|
||||
$crate::ConstValue::Object({
|
||||
let mut object = std::collections::BTreeMap::new();
|
||||
value_internal!(@object object () ($($tt)+) ($($tt)+));
|
||||
$crate::value_internal!(@object object () ($($tt)+) ($($tt)+));
|
||||
object
|
||||
})
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user