Fix subscriptions with custom scalars (#706)

This commit is contained in:
Chris 2020-07-17 03:52:16 -04:00 committed by GitHub
parent e730f6b336
commit f5839c034e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 7 deletions

View file

@ -4,7 +4,7 @@ use juniper::{
execute,
parser::{ParseError, ScalarToken, Spanning, Token},
serde::de,
EmptyMutation, EmptySubscription, InputValue, Object, ParseScalarResult, RootNode, ScalarValue,
EmptyMutation, FieldResult, InputValue, Object, ParseScalarResult, RootNode, ScalarValue,
Value, Variables,
};
use std::fmt;
@ -172,15 +172,24 @@ impl TestType {
}
}
struct TestSubscriptionType;
#[juniper::graphql_subscription(
Scalar = MyScalarValue
)]
impl TestSubscriptionType {
async fn foo(
) -> std::pin::Pin<Box<dyn futures::Stream<Item = FieldResult<i32, MyScalarValue>> + Send>>
{
Box::pin(futures::stream::empty())
}
}
async fn run_variable_query<F>(query: &str, vars: Variables<MyScalarValue>, f: F)
where
F: Fn(&Object<MyScalarValue>) -> (),
{
let schema = RootNode::new(
TestType,
EmptyMutation::<()>::new(),
EmptySubscription::<()>::new(),
);
let schema = RootNode::new(TestType, EmptyMutation::<()>::new(), TestSubscriptionType);
let (result, errs) = execute(query, None, &schema, &vars, &())
.await

View file

@ -1218,7 +1218,7 @@ impl GraphQLTypeDefiniton {
});
Ok(
::juniper::Value::Scalar::<
::juniper::ValuesStream
::juniper::ValuesStream::<#scalar>
>(Box::pin(f))
)
})