Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add subscription support #433

Merged
merged 343 commits into from
Mar 19, 2020
Merged
Show file tree
Hide file tree
Changes from 58 commits
Commits
Show all changes
343 commits
Select commit Hold shift + click to select a range
ab90737
Push errors to executor in `resolve_selection_set_into_iter`
nWacky Oct 22, 2019
2f04ea4
Change 'Arc' to 'Rc' in synchronous context
nWacky Oct 22, 2019
58f8cba
Push errors to executor in `resolve_selection_set_into_stream`
nWacky Oct 22, 2019
cf3b8e2
Comment out all tests, create new test module for subscriptions
nWacky Oct 22, 2019
6b6f7c4
Fix subscription macro
nWacky Oct 22, 2019
4408dcc
Add synchronous test for subscriptions, fix errors in macros, minor r…
nWacky Oct 22, 2019
0434559
Add async subscriptions test
nWacky Oct 23, 2019
40533d8
Add more sync subscription tests, encapsulate sync and async tests to…
nWacky Oct 23, 2019
c0202fb
Encapsulate async subscription creation logic
nWacky Oct 23, 2019
e9b08d5
Format
nWacky Oct 23, 2019
b95191f
Add `into_iter` for `IteratorGraphQLResponse`
nWacky Oct 24, 2019
9794489
Update playground with `into_iter`
nWacky Oct 24, 2019
ca3f321
Tried implementing `into_stream` with poll_next
nWacky Oct 24, 2019
67e0884
Implemented `into_stream`
nWacky Oct 24, 2019
b72cba7
Add `into_stream` to playground, fix bug
nWacky Oct 24, 2019
babff0a
Format
nWacky Oct 24, 2019
18d928c
Add docs, refactor
nWacky Oct 24, 2019
72fcdc4
Add docs to executor_wrappers
nWacky Oct 24, 2019
45194fb
Format [skip ci]
nWacky Oct 25, 2019
2b51dee
Fix warnings in juniper [skip ci]
nWacky Oct 25, 2019
e7ad2c5
Fix compilation error without "async" feature [skip ci]
nWacky Oct 25, 2019
fd6c0ff
Rebase onto `async-await`
nWacky Oct 29, 2019
e577b60
Tests pass [skip ci]
nWacky Oct 29, 2019
430487b
Merge branch 'async-await-subscriptions' of https://github.com/instru…
nWacky Oct 29, 2019
a08b379
Fix rocket playground compilation error [skip ci]
nWacky Oct 29, 2019
3572178
Rebase onto `async_await`
nWacky Oct 30, 2019
5145a8a
Fix error with not displayed results in GraphQL Playground
nWacky Oct 30, 2019
c867b57
Stop returning values after stop signal received
nWacky Oct 30, 2019
109e5a8
Stop stream after stop signal received
nWacky Oct 30, 2019
3bc69ec
Close stream after close message
nWacky Oct 31, 2019
7b720f3
Format, minor refactor
nWacky Oct 31, 2019
7d81472
Resolve variables
nWacky Oct 31, 2019
36110b6
Add instructions how to use variables with subscriptions (playground …
nWacky Oct 31, 2019
7b10956
Format imports, fix warnings, use id from request
nWacky Oct 31, 2019
5a79836
Fix "__Type" not found error in queries
nWacky Oct 31, 2019
068771a
Fix "_EmptySubscription" introspection query errors
nWacky Nov 1, 2019
0bbb537
Update graphql playground version
nWacky Nov 1, 2019
2ada844
Remove all `println`s from `juniper_warp`
nWacky Nov 1, 2019
0234924
Fix warnings, check if `warp_async` compiles without `async` feature …
nWacky Nov 1, 2019
4c0748d
Fix project's cargo.toml [skip ci]
nWacky Nov 1, 2019
7706ebc
Update comment in `warp_subscriptions` [skip ci]
nWacky Nov 1, 2019
7a262ed
Rebase onto `async-await`
nWacky Nov 1, 2019
54d4bec
Merge branch 'async-await-subscriptions' of https://github.com/instru…
nWacky Nov 1, 2019
4debdfb
Rebase onto `master`
nWacky Nov 4, 2019
6bed20f
Format
nWacky Nov 4, 2019
ea474ab
Merge branch 'async-await-subscriptions' of https://github.com/instru…
nWacky Nov 4, 2019
90873ac
Tests pass [skip ci]
nWacky Nov 4, 2019
153a870
Rebase onto `async-await`
nWacky Nov 5, 2019
b1a395c
Merge branch 'async-await-subscriptions' of https://github.com/instru…
nWacky Nov 5, 2019
599747f
Fix warnings and remove unnecessary .len() function for value::Object
tyranron Nov 5, 2019
acd1bf2
Refactor value::Object methods
tyranron Nov 5, 2019
5b1173d
Refactor validation module changes
tyranron Nov 5, 2019
1f1837b
Some corrections [skip ci]
tyranron Nov 5, 2019
2036ba5
Rebase juniper onto master
nWacky Nov 7, 2019
f3ee2c6
Fix warp compilation errors
nWacky Nov 7, 2019
a9d5e93
Merge branch 'async-await-subscriptions' of https://github.com/instru…
nWacky Nov 7, 2019
3a86158
Revert merge
nWacky Nov 7, 2019
365c5ec
Start resolving todo with macro
nWacky Nov 8, 2019
43f3478
Fix tests compilation errors
nWacky Nov 8, 2019
6b48eff
Rebase onto `async-await`
nWacky Nov 8, 2019
e6257b3
Merge branch 'async-await-upstream' into async-await-subscriptions
nWacky Nov 8, 2019
f95e15e
Resolve warnings, add 'as _' to StreamExt, TryStreamExt, FuturesExt
nWacky Nov 8, 2019
6a1a27d
Juniper's tests pass
nWacky Nov 8, 2019
8df420e
Add return types as iterators support for `graphql::subscription` macro
nWacky Nov 8, 2019
be1534e
Format
nWacky Nov 11, 2019
60cc4ff
Format playground
nWacky Nov 11, 2019
fe5bfa4
Reset `juniper_rocket` to async version, fix warnings
nWacky Nov 11, 2019
000e83a
Refactor docs in base.rs
nWacky Nov 11, 2019
39403e4
Add GraphQLTypeAsync manual implementation example
nWacky Nov 11, 2019
a927100
Fix tests
nWacky Nov 11, 2019
9af5d59
Make playground url optional, fix bug in #[juniper::subscription]
nWacky Nov 11, 2019
66e5388
Format, update docs in `async_await`
nWacky Nov 11, 2019
5627d3e
Add test for `test_extract_ok_type_from_std_result`, remove needless …
nWacky Nov 11, 2019
b05cfee
Format [skip ci]
nWacky Nov 11, 2019
76c3efa
Remove IteratorGraphQLResponse::into_iter\StreamGraphQLResponse::into…
nWacky Nov 12, 2019
bd430dd
Resolve error `warp::reject::Reject` not implemented, add #![deny(war…
nWacky Nov 13, 2019
932267f
Add `EmptySubscription` to `juniper_warp` tests
nWacky Nov 13, 2019
ffdfa6e
Rename `fields_count` to `field_count`
nWacky Nov 13, 2019
6a75ca5
User `take_while` in `Object::try_from_iter`
nWacky Nov 13, 2019
ce96a9b
Update docs on subscription macros
nWacky Nov 13, 2019
77d6862
Add FieldResult to `extract_result_segment`
nWacky Nov 13, 2019
c05748b
Use .for_each instead of .then.for_each [skip ci]
nWacky Nov 13, 2019
8e892a6
Remove needless structs from playground [skip ci]
nWacky Nov 13, 2019
2fcb523
Merge branch 'async-await-subscriptions-origin' into async-await-subs…
nWacky Nov 14, 2019
4ae9e44
Remove GraphQLSubscriptionType
nWacky Nov 14, 2019
f9d0ec6
Refactor subscription functions
nWacky Nov 14, 2019
65f10c2
Add default implementation for `StreamGraphQLResponse` back
nWacky Nov 14, 2019
3372df1
Remove `ValuesIterator`
nWacky Nov 14, 2019
92d0b89
Pass fragments vector by value in `Executor`
nWacky Nov 14, 2019
3d250df
Rename `GraphQLSubscriptionTypeAsync` to `GraphQLSubscriptionType`, r…
nWacky Nov 14, 2019
9577bf9
Tried owned executor [does not compile]
nWacky Nov 14, 2019
1c7a356
Add manual GraphQLType implementantion to playground [does not compile]
nWacky Nov 14, 2019
c34a312
Rename `ValuesStream` to `ValuesResultStream`, replace returned value…
nWacky Nov 15, 2019
661ae5e
Rename GraphQLSubscriptionType to GraphQLSubscriptionTypeAsync
nWacky Nov 15, 2019
0fc7532
Start adding better error logic
nWacky Nov 15, 2019
0f71b13
Rewrite resolve_selection_set_into_stream_recursive to return Result<…
nWacky Nov 15, 2019
283e3b4
Return errors, add errors to StreamGraphQLResponse [only juniper comp…
nWacky Nov 15, 2019
4152006
Return errors and close connection from juniper_warp
nWacky Nov 15, 2019
047e092
Try using `SubscriptionsExecutor` instead of `Executor` [does not com…
nWacky Nov 18, 2019
1fb4ada
Keep only necessary things in SubscriptionsExecutor
nWacky Nov 18, 2019
e2dfb54
Revert to 4152006d0d5037e2ce3e6992bef95e692313af71
nWacky Nov 18, 2019
74d303f
Return ExecutionError and return errors over graphql more correctly
nWacky Nov 18, 2019
eb153e9
Start updating macros [does not compile]
nWacky Nov 19, 2019
c90abaa
Resolve only the first item in selection set, panic otherwise. Use Su…
nWacky Nov 19, 2019
f189b89
Use executor in resolver
nWacky Nov 19, 2019
553f694
Format
nWacky Nov 19, 2019
73b3810
Return Null when got error while resolving subscription
nWacky Nov 19, 2019
954f325
resolve fragments on subscriptions
nWacky Nov 19, 2019
56f0d78
Fix bug when resolving fragment spread
nWacky Nov 20, 2019
d17548b
Fix warnings, format
nWacky Nov 20, 2019
d0c9b34
Macros compile
nWacky Nov 20, 2019
6e89673
Move subscriptions logic to separate module
nWacky Nov 20, 2019
3a2cdfe
Add SubscriptionCoordinator and SubscriptionConnection traits, Subscr…
nWacky Nov 20, 2019
f275a2c
Start implementing subscription connection for subscriptions example
nWacky Nov 20, 2019
f80cbbc
Try using Executor instead of SubscriptionsExecutor [only juniper com…
nWacky Nov 21, 2019
9851277
Use `Executor` instead of `SubscriptionsExecutor` in most places and …
nWacky Nov 21, 2019
ceab242
Uncomment resolver logic, fix lifetimes
nWacky Nov 22, 2019
ee6936f
Use Arc for FieldPath
nWacky Nov 22, 2019
0398ec1
Format
nWacky Nov 22, 2019
beadd15
Fix bug with endless loop on empty object
nWacky Nov 22, 2019
de2303b
Fix lifetime mismatch compilation error with fragment spread
nWacky Nov 25, 2019
cb5dc85
Encapsulate FieldError and ExecutionError to StreamError, add derive(…
nWacky Nov 25, 2019
b9d9322
Use Executor's errors vector, update http handlers
nWacky Nov 25, 2019
236452f
Add trait to convert T to Ok(t)
nWacky Nov 26, 2019
6ef4e69
Support both `T` and `Result<T, E>` as field resolvers
nWacky Nov 27, 2019
f32bb3b
Implement GraphQLTraitAsync for T, Result<T>, and T in stream, Result…
nWacky Nov 27, 2019
dc383c9
Encapsualte subscription-related traits to juniper
nWacky Nov 27, 2019
e7c2059
Fix bug with type alias
nWacky Nov 27, 2019
35944d4
Update macros
nWacky Nov 27, 2019
3ef45e8
Return errors from `into_stream` directly
nWacky Nov 27, 2019
f609577
Remove needless cloning
nWacky Nov 27, 2019
f5b99c9
Format
nWacky Nov 27, 2019
ccf0ad2
Pass Executor instead of OwnedExecutor to resolve_field_into_stream
nWacky Nov 27, 2019
c2ead6d
Update macros
nWacky Nov 27, 2019
03c5ed8
Refactor ExecutorDataVariables
nWacky Nov 27, 2019
5b17288
Allow multiple subscriptions to be executed
nWacky Nov 27, 2019
8474a6c
Format, add some docs and todos
nWacky Nov 27, 2019
d41e7d8
Fix warnings
nWacky Nov 28, 2019
d8c3692
Remove SubscriptionCoordinator and SubscriptionConnection
nWacky Nov 28, 2019
e04e2f8
Minor refactor
nWacky Nov 28, 2019
5d0e2b8
Export juniper_codegen::async to #[cfg(feature = "async")]
nWacky Nov 28, 2019
6475747
Mark local todos to todo#433, change all todos to TODO
nWacky Nov 28, 2019
815e442
Resolve local TODOs
nWacky Nov 28, 2019
6f70d1c
Update args.rs todos as in master
nWacky Nov 28, 2019
c0f8d80
Update tests
nWacky Nov 28, 2019
86bee52
Update tests
nWacky Nov 28, 2019
576e876
Rename executor_wrappers to owned_executor, update juniper_codegen todo
nWacky Nov 28, 2019
2ca2026
Format
nWacky Nov 28, 2019
bf0c85d
Lint juniper, clean up playground
nWacky Nov 28, 2019
e40c36e
Remove needless test
nWacky Nov 28, 2019
117860a
Update playgrounds
nWacky Nov 29, 2019
079f6dd
Rebase onto async-await
nWacky Nov 29, 2019
f30c422
Merge branch 'async-await-subscriptions' into async-await-subscriptio…
nWacky Nov 29, 2019
eda2d2b
Fix merge
nWacky Nov 29, 2019
533796b
Start fixing tests
nWacky Nov 29, 2019
ac21584
tests pass
nWacky Nov 29, 2019
9df3a44
Format imports
nWacky Nov 29, 2019
8f2d805
Fix compilation error on `run`
nWacky Nov 29, 2019
975cd9f
Format [skip ci]
nWacky Nov 29, 2019
481b3b5
Exclude subscriptions example from the project tree [skip ci]
nWacky Nov 29, 2019
d8379ac
Rebase onto master
nWacky Jan 27, 2020
a53ab44
Fix juniper compilation errors
nWacky Jan 27, 2020
0815d10
Resolve todos
nWacky Jan 27, 2020
17231bf
Review subscription execution logic
nWacky Jan 28, 2020
f7d23a9
Review subscription execution logic
nWacky Jan 28, 2020
37ede87
Minor refactor
nWacky Jan 28, 2020
cdbafdf
Fix warp and warp example compilation errors
nWacky Jan 28, 2020
faea73d
Format
nWacky Jan 28, 2020
ce56ce2
Fix warnings
nWacky Jan 28, 2020
9e09df3
Rename #[subscription] to #[graphqL_subscription]
nWacky Jan 28, 2020
44549b6
Fix tests compilation errors
nWacky Jan 28, 2020
6f1a5be
Fix test warnings
nWacky Jan 29, 2020
beaf1c8
Resolve todos, uncomment other tests
nWacky Jan 29, 2020
ad22bab
Resolve todos, uncomment and fix other tests
nWacky Jan 29, 2020
e4decf0
Format [skip ci]
nWacky Jan 29, 2020
81166b3
Merge branch 'async-await-subscriptions' of https://github.com/instru…
nWacky Jan 29, 2020
284e9b2
Fix merge [skip ci]
nWacky Jan 29, 2020
02d7176
Merge remote-tracking branch 'origin/master' into async-await-subscri…
nWacky Mar 3, 2020
05e1c8a
Fix compilation errors
nWacky Mar 3, 2020
58824dc
Format
nWacky Mar 3, 2020
a9bd13d
Sketch SubscriptionCoordinator::subscribe
nWacky Mar 3, 2020
263a3af
Create `Coordinator: SubscriptionCoordinator`
nWacky Mar 4, 2020
bb19863
Implement SubscriptionCoordinator::subscribe()
nWacky Mar 4, 2020
5725d4c
Implement Connection
nWacky Mar 4, 2020
a5231a1
Implement demo server, temporatily not return Box<SubscriptionConnect…
nWacky Mar 4, 2020
cbe08fa
Move subscriptions impl to juniper_subscriptions module, tried implem…
nWacky Mar 5, 2020
5f1325a
Delete old Connection implementation
nWacky Mar 5, 2020
02617f9
Implement From<Value::Object<Stream>> for Connection
nWacky Mar 5, 2020
abd8c89
Return Self::Connection from SubscriptionConnection::subscribe
nWacky Mar 5, 2020
584214d
Remove async trait from Subscription
nWacky Mar 6, 2020
12fef56
Format
nWacky Mar 6, 2020
5be6ce1
Resolve warnings and some todos
nWacky Mar 6, 2020
3102a92
Implement other members in `Connection::from_stream`
nWacky Mar 6, 2020
7b6d2b6
Implement Value::Null and Value::Scalar in `Connection::from_stream`
nWacky Mar 6, 2020
3161ed5
Refactor Connection::from_stream, implement value::list
nWacky Mar 6, 2020
75e27ed
Add some docs
nWacky Mar 6, 2020
d09e0ba
Implement fastest_response_stream
nWacky Mar 7, 2020
ce37269
Add docs for juniper_subscriptions
nWacky Mar 7, 2020
7a7e1de
Minor refactor: function names
nWacky Mar 7, 2020
8addc5e
Rebane ValuesResultStream to ValuesStream
nWacky Mar 7, 2020
3c88a45
Resolve todos
nWacky Mar 7, 2020
a28a8fc
Fix compilation errors without async feature
nWacky Mar 7, 2020
bd6595e
Clean up
nWacky Mar 7, 2020
c8ae02c
Format
nWacky Mar 8, 2020
f6b4561
Not panic on errors in juniper_warp
nWacky Mar 9, 2020
71b16fe
Fix error resolving "_schema" query
nWacky Mar 9, 2020
510282b
Add a todo: not panic on nonexisting fields inside GraphQL objects
nWacky Mar 9, 2020
4361a00
Move warp_subscriptions implementation to example
nWacky Mar 10, 2020
6d3feb7
Fix tests errors
nWacky Mar 10, 2020
54fe613
Tried writing tests with subscriptioncooddinator
nWacky Mar 10, 2020
ce7505c
Subscriptions tests pass
nWacky Mar 10, 2020
c7d7d2f
Remove needless todos [skip ci]
nWacky Mar 11, 2020
60594e3
Merge remote-tracking branch 'origin/async-await-subscriptions' into …
nWacky Mar 11, 2020
f29e621
Fix merge
nWacky Mar 11, 2020
5f69876
Merge remote-tracking branch 'upstream/master' into async-await-subsc…
nWacky Mar 11, 2020
f0a1a31
Fix merge
nWacky Mar 11, 2020
e53c062
Format
nWacky Mar 11, 2020
500cb10
Clean up, add todos [skip ci]
nWacky Mar 11, 2020
d027221
Fix tests failure
nWacky Mar 11, 2020
4bc481f
Add juniper_subscriptions tests
nWacky Mar 12, 2020
bcd5978
Clean up juniper_subscriptions::whole_values_stream logic
nWacky Mar 12, 2020
9737394
Format
nWacky Mar 12, 2020
7785ad7
Refactor
nWacky Mar 12, 2020
5bd8462
Refactor warp_subscriptions
nWacky Mar 13, 2020
da0138c
Subscription tests pass
nWacky Mar 13, 2020
b0b9486
Rebase warp_async
nWacky Mar 13, 2020
a7a1941
Refactor
nWacky Mar 15, 2020
63287a5
Add subscription macros tests
nWacky Mar 15, 2020
65e3047
Merge remote-tracking branch 'upstream/master' into async-await-subsc…
nWacky Mar 15, 2020
6863e4c
Fix merge
nWacky Mar 15, 2020
a7b537e
Update changelog and docs, minor refactor
nWacky Mar 15, 2020
aa27e42
Fix CI
nWacky Mar 15, 2020
21dac57
Format
nWacky Mar 15, 2020
a1656ee
Update changelogs
nWacky Mar 15, 2020
963f5e1
Apply suggestions
nWacky Mar 16, 2020
f86cf8b
Apply review suggestions
nWacky Mar 16, 2020
f837582
Refactor warp_subscriptions
nWacky Mar 17, 2020
66b5fc1
Fix tests
nWacky Mar 17, 2020
994440e
Add poll_fn back
nWacky Mar 17, 2020
5d0d5e8
Format
nWacky Mar 17, 2020
c56dbf4
Not exclude warp
nWacky Mar 17, 2020
b6ed979
Move graphql_subscriptions to juniper_warp
nWacky Mar 17, 2020
b0392ed
Update book and benches
nWacky Mar 17, 2020
2962ef7
Add type to EmptySubcription
nWacky Mar 17, 2020
67ba411
Fix book compile error
nWacky Mar 17, 2020
b62c339
Add subscriptions to release.toml
nWacky Mar 18, 2020
e3070e2
Merge remote-tracking branch 'upstream/master' into async-await-subsc…
nWacky Mar 18, 2020
c5e5fe9
Remove futures01 from juniper_warp
nWacky Mar 18, 2020
fcb0082
Format
nWacky Mar 18, 2020
1baa24f
Fix cargo.toml
nWacky Mar 18, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
616 changes: 566 additions & 50 deletions juniper/src/executor/mod.rs

Large diffs are not rendered by default.

94 changes: 85 additions & 9 deletions juniper/src/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ use crate::{
executor::ExecutionError,
value::{DefaultScalarValue, ScalarRefValue, ScalarValue},
FieldError, GraphQLError, GraphQLType, RootNode, Value, Variables,
ValuesIterator, ValuesStream,
};
use crate::executor::OwnedExecutor;

/// The expected structure of the decoded JSON document for either POST or GET requests.
///
Expand Down Expand Up @@ -70,19 +72,75 @@ where
}
}

/// Execute a GraphQL request using the specified schema and context
/// Execute a GraphQL subscription using the specified schema and context
///
/// This is a simple wrapper around the `execute` function exposed at the
/// This is a simple wrapper around the `subscribe` function exposed at the
/// top level of this crate.
pub fn execute<'a, CtxT, QueryT, MutationT>(
pub fn subscribe<'a, CtxT, QueryT, MutationT, SubscriptionT>(
&'a self,
root_node: &'a RootNode<QueryT, MutationT, S>,
root_node: &'a RootNode<QueryT, MutationT, SubscriptionT, S>,
context: &'a CtxT,
executor_variables: &'a mut OwnedExecutor<'a, CtxT, S>,
fragments: &'a mut Vec<crate::parser::Spanning<crate::ast::Fragment<'a, S>>>,
executor: &'a mut crate::executor::OptionalExecutor<'a, CtxT, S>,
) -> IteratorGraphQLResponse<'a, S>
where
S: ScalarValue + Send + Sync + 'static,
QueryT: GraphQLType<S, Context = CtxT>,
MutationT: GraphQLType<S, Context = CtxT>,
SubscriptionT: crate::SubscriptionHandler<S, Context = CtxT>,
for<'b> &'b S: ScalarRefValue<'b>,
{
IteratorGraphQLResponse(crate::subscribe(
&self.query,
self.operation_name(),
root_node,
self.variables(),
context,
executor_variables,
fragments,
executor,
))
}

/// Execute a GraphQL subscription using the specified schema and context
///
/// This is a simple wrapper around the `subscribe_async` function exposed at the
/// top level of this crate.
#[cfg(feature = "async")]
pub async fn subscribe_async<'a, CtxT, QueryT, MutationT, SubscriptionT>(
&'a self,
root_node: &'a RootNode<'a, QueryT, MutationT, SubscriptionT, S>,
context: &'a CtxT,
) -> StreamGraphQLResponse<'a, S>
where
S: ScalarValue + Send + Sync + 'static,
QueryT: crate::GraphQLTypeAsync<S, Context = CtxT> + Send + Sync,
QueryT::TypeInfo: Send + Sync,
MutationT: crate::GraphQLTypeAsync<S, Context = CtxT> + Send + Sync,
MutationT::TypeInfo: Send + Sync,
SubscriptionT: crate::SubscriptionHandlerAsync<S, Context = CtxT> + Send + Sync,
SubscriptionT::TypeInfo: Send + Sync,
CtxT: Send + Sync,
for<'b> &'b S: ScalarRefValue<'b>,
{
let op = self.operation_name();
let vars = &self.variables();
let res = crate::subscribe_async(&self.query, op, root_node, vars, context).await;

StreamGraphQLResponse(res)
}

pub fn execute<'a, CtxT, QueryT, MutationT, SubscriptionT>(
&'a self,
root_node: &'a RootNode<QueryT, MutationT, SubscriptionT, S>,
context: &CtxT,
) -> GraphQLResponse<'a, S>
where
S: ScalarValue,
S: ScalarValue + Send + Sync + 'static,
QueryT: GraphQLType<S, Context = CtxT>,
MutationT: GraphQLType<S, Context = CtxT>,
SubscriptionT: crate::SubscriptionHandler<S, Context = CtxT>,
for<'b> &'b S: ScalarRefValue<'b>,
{
GraphQLResponse(crate::execute(
Expand All @@ -95,17 +153,19 @@ where
}

#[cfg(feature = "async")]
pub async fn execute_async<'a, CtxT, QueryT, MutationT>(
pub async fn execute_async<'a, CtxT, QueryT, MutationT, SubscriptionT>(
&'a self,
root_node: &'a RootNode<'a, QueryT, MutationT, S>,
root_node: &'a RootNode<'a, QueryT, MutationT, SubscriptionT, S>,
context: &'a CtxT,
) -> GraphQLResponse<'a, S>
where
S: ScalarValue + Send + Sync,
S: ScalarValue + Send + Sync + 'static,
QueryT: crate::GraphQLTypeAsync<S, Context = CtxT> + Send + Sync,
QueryT::TypeInfo: Send + Sync,
MutationT: crate::GraphQLTypeAsync<S, Context = CtxT> + Send + Sync,
MutationT::TypeInfo: Send + Sync,
SubscriptionT: crate::SubscriptionHandlerAsync<S, Context = CtxT> + Send + Sync,
SubscriptionT::TypeInfo: Send + Sync,
CtxT: Send + Sync,
for<'b> &'b S: ScalarRefValue<'b>,
{
Expand All @@ -122,9 +182,25 @@ where
/// to JSON and send it over the wire. Use the `is_ok` method to determine
/// whether to send a 200 or 400 HTTP status code.
pub struct GraphQLResponse<'a, S = DefaultScalarValue>(
Result<(Value<S>, Vec<ExecutionError<S>>), GraphQLError<'a>>,
//todo: remove pub (pub is used in playground to access result)
pub Result<(Value<S>, Vec<ExecutionError<S>>), GraphQLError<'a>>,
);

//todo: remove pub (pub is used in playground to access result)
pub struct IteratorGraphQLResponse<'a, S = DefaultScalarValue>(
pub Result<(Value<ValuesIterator<'a, S>>, Vec<ExecutionError<S>>), GraphQLError<'a>>,
)
where
S: 'static;

#[cfg(feature = "async")]
pub struct StreamGraphQLResponse<'a, S = DefaultScalarValue>(
//todo: remove pub (pub is used in playground to access result)
pub Result<(Value<ValuesStream<S>>, Vec<ExecutionError<S>>), GraphQLError<'a>>,
)
where
S: 'static;

impl<'a, S> GraphQLResponse<'a, S>
where
S: ScalarValue,
Expand Down
6 changes: 5 additions & 1 deletion juniper/src/integrations/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ impl<'a> ser::Serialize for GraphQLError<'a> {
message: "Expected query, got subscription",
}]
.serialize(serializer),
GraphQLError::NotSubscription => [SerializeHelper {
message: "Expected subscription, got query",
}]
.serialize(serializer),
}
}
}
Expand Down Expand Up @@ -408,7 +412,7 @@ mod tests {
use super::{ExecutionError, GraphQLError};
use crate::{
ast::InputValue,
value::{DefaultScalarValue, Object},
value::{base_object::SyncObject, DefaultScalarValue, Object},
FieldError, Value,
};
use serde_json::{from_str, to_string};
Expand Down
159 changes: 137 additions & 22 deletions juniper/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ pub mod integrations;
// TODO: remove this alias export in 0.10. (breaking change)
pub use crate::http::graphiql;

pub use crate::executor::OptionalExecutor;


#[cfg(all(test, not(feature = "expose-test-schema")))]
mod tests;
#[cfg(feature = "expose-test-schema")]
Expand Down Expand Up @@ -175,12 +178,27 @@ pub use crate::{
},
};

pub use executor::OwnedExecutor;

/// A pinned, boxed future that can be polled.
pub type BoxFuture<'a, T> = std::pin::Pin<Box<dyn std::future::Future<Output = T> + 'a + Send>>;

#[cfg(feature = "async")]
pub use crate::types::async_await::GraphQLTypeAsync;

#[cfg(feature = "async")]
pub use crate::executor::SubscriptionResultAsync;

pub use crate::executor::SubscriptionResult;
#[cfg(feature = "async")]
pub use crate::types::async_await::SubscriptionHandlerAsync;

pub use crate::types::base::SubscriptionHandler;

pub use crate::executor::ValuesIterator;
#[cfg(feature = "async")]
pub use crate::executor::ValuesStream;

/// An error that prevented query execution
#[derive(Debug, PartialEq)]
#[allow(missing_docs)]
Expand All @@ -191,21 +209,20 @@ pub enum GraphQLError<'a> {
MultipleOperationsProvided,
UnknownOperationName,
IsSubscription,
NotSubscription,
}

/// Execute a query in a provided schema
pub fn execute<'a, S, CtxT, QueryT, MutationT>(
fn parse_and_validate_document<'a, QueryT, MutationT, SubscriptionT, CtxT, S>(
document_source: &'a str,
operation_name: Option<&str>,
root_node: &'a RootNode<QueryT, MutationT, S>,
root_node: &'a RootNode<QueryT, MutationT, SubscriptionT, S>,
variables: &Variables<S>,
context: &CtxT,
) -> Result<(Value<S>, Vec<ExecutionError<S>>), GraphQLError<'a>>
) -> Result<Vec<crate::ast::Definition<'a, S>>, GraphQLError<'a>>
where
S: ScalarValue,
S: ScalarValue + Send + Sync + 'static,
for<'b> &'b S: ScalarRefValue<'b>,
QueryT: GraphQLType<S, Context = CtxT>,
MutationT: GraphQLType<S, Context = CtxT>,
SubscriptionT: crate::SubscriptionHandler<S, Context = CtxT>,
{
let document = parse_document_source(document_source, &root_node.schema)?;
{
Expand All @@ -226,26 +243,25 @@ where
}
}

executor::execute_validated_query(document, operation_name, root_node, variables, context)
Ok(document)
}

/// Execute a query in a provided schema
#[cfg(feature = "async")]
pub async fn execute_async<'a, S, CtxT, QueryT, MutationT>(
fn parse_and_validate_document_async<'a, QueryT, MutationT, SubscriptionT, CtxT, S>(
document_source: &'a str,
operation_name: Option<&str>,
root_node: &'a RootNode<'a, QueryT, MutationT, S>,
root_node: &'a RootNode<QueryT, MutationT, SubscriptionT, S>,
variables: &Variables<S>,
context: &CtxT,
) -> Result<(Value<S>, Vec<ExecutionError<S>>), GraphQLError<'a>>
) -> Result<Vec<crate::ast::Definition<'a, S>>, GraphQLError<'a>>
where
S: ScalarValue + Send + Sync,
QueryT: GraphQLTypeAsync<S, Context = CtxT> + Send + Sync,
S: ScalarValue + Send + Sync + 'static,
for<'b> &'b S: ScalarRefValue<'b>,
QueryT: GraphQLTypeAsync<S, Context = CtxT>,
QueryT::TypeInfo: Send + Sync,
MutationT: GraphQLTypeAsync<S, Context = CtxT> + Send + Sync,
MutationT: GraphQLTypeAsync<S, Context = CtxT>,
MutationT::TypeInfo: Send + Sync,
SubscriptionT: crate::SubscriptionHandlerAsync<S, Context = CtxT>,
SubscriptionT::Context: Send + Sync,
SubscriptionT::TypeInfo: Send + Sync,
CtxT: Send + Sync,
for<'b> &'b S: ScalarRefValue<'b>,
{
let document = parse_document_source(document_source, &root_node.schema)?;
{
Expand All @@ -266,21 +282,120 @@ where
}
}

Ok(document)
}

/// Execute a query in a provided schema
pub fn execute<'a, S, CtxT, QueryT, MutationT, SubscriptionT>(
document_source: &'a str,
operation_name: Option<&str>,
root_node: &'a RootNode<QueryT, MutationT, SubscriptionT, S>,
variables: &Variables<S>,
context: &CtxT,
) -> Result<(Value<S>, Vec<ExecutionError<S>>), GraphQLError<'a>>
where
S: ScalarValue + Send + Sync + 'static,
for<'b> &'b S: ScalarRefValue<'b>,
QueryT: GraphQLType<S, Context = CtxT>,
MutationT: GraphQLType<S, Context = CtxT>,
SubscriptionT: crate::SubscriptionHandler<S, Context = CtxT>,
{
let document = parse_and_validate_document(document_source, root_node, variables)?;

executor::execute_validated_query(document, operation_name, root_node, variables, context)
}

pub fn subscribe<'a, S, CtxT, QueryT, MutationT, SubscriptionT>(
document_source: &'a str,
operation_name: Option<&str>,
root_node: &'a RootNode<'a, QueryT, MutationT, SubscriptionT, S>,
variables: Variables<S>,
context: &'a CtxT,
executor_variables: &'a mut OwnedExecutor<'a, CtxT, S>,
fragments: &'a mut Vec<Spanning<crate::ast::Fragment<'a, S>>>,
executor: &'a mut crate::executor::OptionalExecutor<'a, CtxT, S>,
) -> Result<(Value<ValuesIterator<'a, S>>, Vec<ExecutionError<S>>), GraphQLError<'a>>
where
S: ScalarValue + Send + Sync + 'static,
for<'b> &'b S: ScalarRefValue<'b>,
QueryT: GraphQLType<S, Context = CtxT>,
MutationT: GraphQLType<S, Context = CtxT>,
SubscriptionT: crate::SubscriptionHandler<S, Context = CtxT>,
{
let document = parse_and_validate_document(document_source, root_node, &variables)?;

executor::execute_validated_subcription(document, operation_name, root_node, variables, context, executor_variables, fragments, executor)
}

/// Execute a query in a provided schema
#[cfg(feature = "async")]
pub async fn execute_async<'a, S, CtxT, QueryT, MutationT, SubscriptionT>(
document_source: &'a str,
operation_name: Option<&str>,
root_node: &'a RootNode<'a, QueryT, MutationT, SubscriptionT, S>,
variables: &Variables<S>,
context: &CtxT,
) -> Result<(Value<S>, Vec<ExecutionError<S>>), GraphQLError<'a>>
where
S: ScalarValue + Send + Sync + 'static,
QueryT: GraphQLTypeAsync<S, Context = CtxT> + Send + Sync,
QueryT::TypeInfo: Send + Sync,
MutationT: GraphQLTypeAsync<S, Context = CtxT> + Send + Sync,
MutationT::TypeInfo: Send + Sync,
SubscriptionT: SubscriptionHandlerAsync<S, Context = CtxT> + Send + Sync,
SubscriptionT::TypeInfo: Send + Sync,
CtxT: Send + Sync,
for<'b> &'b S: ScalarRefValue<'b>,
{
let document = parse_and_validate_document_async(document_source, root_node, variables)?;

executor::execute_validated_query_async(document, operation_name, root_node, variables, context)
.await
}

#[cfg(feature = "async")]
pub async fn subscribe_async<'a, S, CtxT, QueryT, MutationT, SubscriptionT>(
document_source: &'a str,
operation_name: Option<&str>,
root_node: &'a RootNode<'a, QueryT, MutationT, SubscriptionT, S>,
variables: &Variables<S>,
context: &CtxT,
) -> Result<(Value<ValuesStream<S>>, Vec<ExecutionError<S>>), GraphQLError<'a>>
where
S: ScalarValue + Send + Sync + 'static,
QueryT: GraphQLTypeAsync<S, Context = CtxT> + Send + Sync,
QueryT::TypeInfo: Send + Sync,
MutationT: GraphQLTypeAsync<S, Context = CtxT> + Send + Sync,
MutationT::TypeInfo: Send + Sync,
SubscriptionT: SubscriptionHandlerAsync<S, Context = CtxT> + Send + Sync,
SubscriptionT::TypeInfo: Send + Sync,
CtxT: Send + Sync,
for<'b> &'b S: ScalarRefValue<'b>,
{
let document = parse_and_validate_document_async(document_source, root_node, variables)?;

executor::execute_validated_subscription_async(
document,
operation_name,
root_node,
variables,
context,
)
.await
}

/// Execute the reference introspection query in the provided schema
pub fn introspect<'a, S, CtxT, QueryT, MutationT>(
root_node: &'a RootNode<QueryT, MutationT, S>,
pub fn introspect<'a, S, CtxT, QueryT, MutationT, SubscriptionT>(
root_node: &'a RootNode<QueryT, MutationT, SubscriptionT, S>,
context: &CtxT,
format: IntrospectionFormat,
) -> Result<(Value<S>, Vec<ExecutionError<S>>), GraphQLError<'a>>
where
S: ScalarValue,
S: ScalarValue + Send + Sync + 'static,
for<'b> &'b S: ScalarRefValue<'b>,
QueryT: GraphQLType<S, Context = CtxT>,
MutationT: GraphQLType<S, Context = CtxT>,
SubscriptionT: crate::SubscriptionHandler<S, Context = CtxT>,
{
execute(
match format {
Expand Down
Loading