From 83ffa591845b09dd1c96350434534e8cf4e1f847 Mon Sep 17 00:00:00 2001 From: Lee Benson Date: Thu, 27 Aug 2020 11:01:39 +0100 Subject: [PATCH] Update merging_objects.md Add subscription merging --- docs/en/src/merging_objects.md | 41 ++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/docs/en/src/merging_objects.md b/docs/en/src/merging_objects.md index bc94a416..7756d787 100644 --- a/docs/en/src/merging_objects.md +++ b/docs/en/src/merging_objects.md @@ -22,6 +22,8 @@ Instead, the `#[derive(GQLMergedObject)]` macro allows you to split an object's **Tip:** Every `#[Object]` needs a unique name even in a GQLMergedObject so make sure to give each object your merging it's own name. +**Note:** This works for queries and mutations. For subscriptions, see "Merging Subscriptions" below. + ```rust #[Object] impl UserQuery { @@ -46,3 +48,42 @@ let schema = Schema::new( EmptySubscription ); ``` + +# Merging Subscriptions + +Along with `GQLMergedObject`, you can derive `GQLMergedSubscription` to merge separate `#[Subscription]` blocks. + +Like merging Objects, each subscription block requires a unique name. + +Example: + +```rust +#[derive(Default)] +struct Subscription1; + +#[Subscription] +impl Subscription1 { + async fn events1(&self) -> impl Stream { + futures::stream::iter(0..10) + } +} + +#[derive(Default)] +struct Subscription2; + +#[Subscription] +impl Subscription2 { + async fn events2(&self) -> impl Stream { + futures::stream::iter(10..20) + } +} + +#[derive(GQLMergedSubscription, Default)] +struct Subscription(Subscription1, Subscription2); + +let schema = Schema::new( + Query::default(), + EmptyMutation, + Subscription::default() +); +```