Skip to content

Commit

Permalink
feat: added test to verify serde_json::Value work as subscription ret…
Browse files Browse the repository at this point in the history
…urn type.
  • Loading branch information
chirino committed Aug 16, 2021
1 parent 2e8b326 commit be3a32d
Show file tree
Hide file tree
Showing 2 changed files with 210 additions and 83 deletions.
60 changes: 60 additions & 0 deletions integration_tests/juniper_tests/src/codegen/subscription_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1797,4 +1797,64 @@ mod executor {
)),
);
}

#[tokio::test]
async fn test_integration_json() {
use juniper::integrations::json::{TypedJson, TypedJsonInfo};
use serde_json::json;

struct Foo;
impl TypedJsonInfo for Foo {
fn type_name() -> &'static str {
"Foo"
}
fn schema() -> &'static str {
r#"
type Foo {
message: [String]
}
"#
}
}

struct Query;
#[graphql_object()]
impl Query {
fn zero() -> FieldResult<i32> {
Ok(0)
}
}

struct Subscription;
#[graphql_subscription(scalar = S: ScalarValue)]
impl Subscription {
// TODO: Make work for `Stream<'e, &'e str>`.
async fn foo<'e, S>(
&self,
_executor: &'e Executor<'_, '_, (), S>,
) -> Stream<'static, TypedJson<Foo>>
where
S: ScalarValue,
{
let data = TypedJson::new(json!({"message": ["Hello World"] }));
Box::pin(stream::once(future::ready(data)))
}
}

let schema = juniper::RootNode::new(Query, EmptyMutation::new(), Subscription);

const DOC: &str = r#"subscription {
foo { message }
}"#;

assert_eq!(
resolve_into_stream(DOC, None, &schema, &Variables::new(), &())
.then(|s| extract_next(s))
.await,
Ok((
graphql_value!({"foo":{"message": ["Hello World"] }}),
vec![]
)),
);
}
}
Loading

0 comments on commit be3a32d

Please sign in to comment.