@@ -13,13 +13,13 @@ the subscriptions to those listeners.
1313Subscriptions are created by calling the ` Request::subscribe ` method in
1414[ GraphQLService.h] ( ../include/graphqlservice/GraphQLService.h ) :
1515``` cpp
16- GRAPHQLSERVICE_EXPORT AwaitableSubscribe subscribe (RequestSubscribeParams params);
16+ GRAPHQLSERVICE_EXPORT [[nodiscard]] AwaitableSubscribe subscribe (RequestSubscribeParams params);
1717```
1818
1919You need to fill in a `RequestSubscribeParams` struct with the subscription event
2020callback, the [parsed](./parsing.md) `query` and any other relevant operation parameters:
2121```cpp
22- struct RequestSubscribeParams
22+ struct [[nodiscard]] RequestSubscribeParams
2323{
2424 // Callback which receives the event data.
2525 SubscriptionCallback callback;
@@ -34,6 +34,9 @@ struct RequestSubscribeParams
3434
3535 // Optional sub-class of RequestState which will be passed to each resolver and field accessor.
3636 std::shared_ptr<RequestState> state;
37+
38+ // Optional override for the default Subscription operation object.
39+ std::shared_ptr<const Object> subscriptionObject {};
3740};
3841```
3942
@@ -61,19 +64,22 @@ The `internal::Awaitable<T>` template is described in [awaitable.md](./awaitable
6164Subscriptions are removed by calling the ` Request::unsubscribe ` method in
6265[ GraphQLService.h] ( ../include/graphqlservice/GraphQLService.h ) :
6366``` cpp
64- GRAPHQLSERVICE_EXPORT AwaitableUnsubscribe unsubscribe (RequestUnsubscribeParams params);
67+ GRAPHQLSERVICE_EXPORT [[nodiscard]] AwaitableUnsubscribe unsubscribe (RequestUnsubscribeParams params);
6568```
6669
6770You need to fill in a `RequestUnsubscribeParams` struct with the `SubscriptionKey`
6871returned by `Request::subscribe` in `AwaitableSubscribe`:
6972```cpp
70- struct RequestUnsubscribeParams
73+ struct [[nodiscard]] RequestUnsubscribeParams
7174{
7275 // Key returned by a previous call to subscribe.
7376 SubscriptionKey key;
7477
7578 // Optional async execution awaitable.
7679 await_async launch;
80+
81+ // Optional override for the default Subscription operation object.
82+ std::shared_ptr<const Object> subscriptionObject {};
7783};
7884```
7985
@@ -83,12 +89,12 @@ By default, the resolvers will run on the same thread synchronously.
8389## ` ResolverContext::NotifySubscribe ` and ` ResolverContext::NotifyUnsubscribe `
8490
8591If you provide a default instance of the ` Subscription ` object to the ` Request ` /
86- ` Operations ` constructor, you will get additional callbacks with the
87- ` ResolverContext::NotifySubscribe ` and ` ResolverContext::NotifyUnsubscribe ` values
88- for the ` FieldParams::resolverContext ` member. These are passed by the
89- ` subscribe ` and ` unsubscribe ` calls to the default subscription object, and
90- they provide an opportunity to acquire or release resources that are required
91- to implement the subscription.
92+ ` Operations ` constructor, or in the ` RequestSubscribeParams ` / ` RequestUnsubscribeParams `
93+ struct, you will get additional callbacks with the ` ResolverContext::NotifySubscribe `
94+ and ` ResolverContext::NotifyUnsubscribe ` values for the ` FieldParams::resolverContext `
95+ member. These are passed by the ` subscribe ` and ` unsubscribe ` calls to the default
96+ subscription object, and they provide an opportunity to acquire or release resources
97+ that are required to implement the subscription.
9298
9399You can provide separate implementations of the ` Subscription ` object as the
94100default in the ` Operations ` constructor and as the payload of a specific
@@ -111,7 +117,7 @@ The `Request::deliver` method determines which subscriptions should receive
111117an event based on several factors, which makes the `RequestDeliverParams` struct
112118more complicated:
113119```cpp
114- struct RequestDeliverParams
120+ struct [[nodiscard]] RequestDeliverParams
115121{
116122 // Deliver to subscriptions on this field.
117123 std::string_view field;
@@ -149,7 +155,7 @@ using SubscriptionArguments = std::map<std::string_view, response::Value>;
149155using SubscriptionArgumentFilterCallback = std::function<bool (response::MapType::const_reference)>;
150156using SubscriptionDirectiveFilterCallback = std::function<bool (Directives::const_reference)>;
151157
152- struct SubscriptionFilter
158+ struct [[nodiscard]] SubscriptionFilter
153159{
154160 // Optional field argument filter, which can either be a set of required arguments, or a
155161 // callback which returns true if the arguments match custom criteria.
@@ -180,6 +186,6 @@ that, there's a public `Request::findOperationDefinition` method which returns
180186the operation type as a ` std::string_view ` along with a pointer to the AST node
181187for the selected operation in the parsed query:
182188``` cpp
183- GRAPHQLSERVICE_EXPORT std::pair<std::string_view, const peg::ast_node*> findOperationDefinition (
184- peg::ast& query, std::string_view operationName) const;
189+ GRAPHQLSERVICE_EXPORT [[nodiscard]] std::pair<std::string_view, const peg::ast_node*>
190+ findOperationDefinition ( peg::ast& query, std::string_view operationName) const;
185191```
0 commit comments