Update subscription test
This commit is contained in:
parent
8647688ab5
commit
a4a1db4836
|
@ -161,6 +161,16 @@ pub async fn test_subscription_with_ctx_data() {
|
||||||
#[Object]
|
#[Object]
|
||||||
impl QueryRoot {}
|
impl QueryRoot {}
|
||||||
|
|
||||||
|
struct MyObject;
|
||||||
|
|
||||||
|
#[Object]
|
||||||
|
impl MyObject {
|
||||||
|
#[field]
|
||||||
|
async fn value(&self, ctx: &Context<'_>) -> i32 {
|
||||||
|
*ctx.data::<i32>()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct SubscriptionRoot;
|
struct SubscriptionRoot;
|
||||||
|
|
||||||
#[Subscription]
|
#[Subscription]
|
||||||
|
@ -170,6 +180,11 @@ pub async fn test_subscription_with_ctx_data() {
|
||||||
let value = *ctx.data::<i32>();
|
let value = *ctx.data::<i32>();
|
||||||
futures::stream::once(async move { value })
|
futures::stream::once(async move { value })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[field]
|
||||||
|
async fn objects(&self) -> impl Stream<Item = MyObject> {
|
||||||
|
futures::stream::once(async move { MyObject })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let schema = Schema::new(QueryRoot, EmptyMutation, SubscriptionRoot);
|
let schema = Schema::new(QueryRoot, EmptyMutation, SubscriptionRoot);
|
||||||
|
@ -177,7 +192,7 @@ pub async fn test_subscription_with_ctx_data() {
|
||||||
{
|
{
|
||||||
let mut stream = schema
|
let mut stream = schema
|
||||||
.create_subscription_stream(
|
.create_subscription_stream(
|
||||||
"subscription { values }",
|
"subscription { values objects { value } }",
|
||||||
None,
|
None,
|
||||||
Default::default(),
|
Default::default(),
|
||||||
Some(Arc::new({
|
Some(Arc::new({
|
||||||
|
@ -192,6 +207,10 @@ pub async fn test_subscription_with_ctx_data() {
|
||||||
Some(serde_json::json!({ "values": 100 })),
|
Some(serde_json::json!({ "values": 100 })),
|
||||||
stream.next().await
|
stream.next().await
|
||||||
);
|
);
|
||||||
|
assert_eq!(
|
||||||
|
Some(serde_json::json!({ "objects": { "value": 100 } })),
|
||||||
|
stream.next().await
|
||||||
|
);
|
||||||
assert!(stream.next().await.is_none());
|
assert!(stream.next().await.is_none());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user