Skip to content

Commit be3a32d

Browse files
committed
feat: added test to verify serde_json::Value work as subscription return type.
1 parent 2e8b326 commit be3a32d

File tree

2 files changed

+210
-83
lines changed

2 files changed

+210
-83
lines changed

integration_tests/juniper_tests/src/codegen/subscription_attr.rs

+60
Original file line numberDiff line numberDiff line change
@@ -1797,4 +1797,64 @@ mod executor {
17971797
)),
17981798
);
17991799
}
1800+
1801+
#[tokio::test]
1802+
async fn test_integration_json() {
1803+
use juniper::integrations::json::{TypedJson, TypedJsonInfo};
1804+
use serde_json::json;
1805+
1806+
struct Foo;
1807+
impl TypedJsonInfo for Foo {
1808+
fn type_name() -> &'static str {
1809+
"Foo"
1810+
}
1811+
fn schema() -> &'static str {
1812+
r#"
1813+
type Foo {
1814+
message: [String]
1815+
}
1816+
"#
1817+
}
1818+
}
1819+
1820+
struct Query;
1821+
#[graphql_object()]
1822+
impl Query {
1823+
fn zero() -> FieldResult<i32> {
1824+
Ok(0)
1825+
}
1826+
}
1827+
1828+
struct Subscription;
1829+
#[graphql_subscription(scalar = S: ScalarValue)]
1830+
impl Subscription {
1831+
// TODO: Make work for `Stream<'e, &'e str>`.
1832+
async fn foo<'e, S>(
1833+
&self,
1834+
_executor: &'e Executor<'_, '_, (), S>,
1835+
) -> Stream<'static, TypedJson<Foo>>
1836+
where
1837+
S: ScalarValue,
1838+
{
1839+
let data = TypedJson::new(json!({"message": ["Hello World"] }));
1840+
Box::pin(stream::once(future::ready(data)))
1841+
}
1842+
}
1843+
1844+
let schema = juniper::RootNode::new(Query, EmptyMutation::new(), Subscription);
1845+
1846+
const DOC: &str = r#"subscription {
1847+
foo { message }
1848+
}"#;
1849+
1850+
assert_eq!(
1851+
resolve_into_stream(DOC, None, &schema, &Variables::new(), &())
1852+
.then(|s| extract_next(s))
1853+
.await,
1854+
Ok((
1855+
graphql_value!({"foo":{"message": ["Hello World"] }}),
1856+
vec![]
1857+
)),
1858+
);
1859+
}
18001860
}

0 commit comments

Comments
 (0)