@@ -13,13 +13,13 @@ the subscriptions to those listeners.
13
13
Subscriptions are created by calling the ` Request::subscribe ` method in
14
14
[ GraphQLService.h] ( ../include/graphqlservice/GraphQLService.h ) :
15
15
``` cpp
16
- GRAPHQLSERVICE_EXPORT AwaitableSubscribe subscribe (RequestSubscribeParams params);
16
+ GRAPHQLSERVICE_EXPORT [[nodiscard]] AwaitableSubscribe subscribe (RequestSubscribeParams params);
17
17
```
18
18
19
19
You need to fill in a `RequestSubscribeParams` struct with the subscription event
20
20
callback, the [parsed](./parsing.md) `query` and any other relevant operation parameters:
21
21
```cpp
22
- struct RequestSubscribeParams
22
+ struct [[nodiscard]] RequestSubscribeParams
23
23
{
24
24
// Callback which receives the event data.
25
25
SubscriptionCallback callback;
@@ -34,6 +34,9 @@ struct RequestSubscribeParams
34
34
35
35
// Optional sub-class of RequestState which will be passed to each resolver and field accessor.
36
36
std::shared_ptr<RequestState> state;
37
+
38
+ // Optional override for the default Subscription operation object.
39
+ std::shared_ptr<const Object> subscriptionObject {};
37
40
};
38
41
```
39
42
@@ -61,19 +64,22 @@ The `internal::Awaitable<T>` template is described in [awaitable.md](./awaitable
61
64
Subscriptions are removed by calling the ` Request::unsubscribe ` method in
62
65
[ GraphQLService.h] ( ../include/graphqlservice/GraphQLService.h ) :
63
66
``` cpp
64
- GRAPHQLSERVICE_EXPORT AwaitableUnsubscribe unsubscribe (RequestUnsubscribeParams params);
67
+ GRAPHQLSERVICE_EXPORT [[nodiscard]] AwaitableUnsubscribe unsubscribe (RequestUnsubscribeParams params);
65
68
```
66
69
67
70
You need to fill in a `RequestUnsubscribeParams` struct with the `SubscriptionKey`
68
71
returned by `Request::subscribe` in `AwaitableSubscribe`:
69
72
```cpp
70
- struct RequestUnsubscribeParams
73
+ struct [[nodiscard]] RequestUnsubscribeParams
71
74
{
72
75
// Key returned by a previous call to subscribe.
73
76
SubscriptionKey key;
74
77
75
78
// Optional async execution awaitable.
76
79
await_async launch;
80
+
81
+ // Optional override for the default Subscription operation object.
82
+ std::shared_ptr<const Object> subscriptionObject {};
77
83
};
78
84
```
79
85
@@ -83,12 +89,12 @@ By default, the resolvers will run on the same thread synchronously.
83
89
## ` ResolverContext::NotifySubscribe ` and ` ResolverContext::NotifyUnsubscribe `
84
90
85
91
If 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.
92
98
93
99
You can provide separate implementations of the ` Subscription ` object as the
94
100
default in the ` Operations ` constructor and as the payload of a specific
@@ -111,7 +117,7 @@ The `Request::deliver` method determines which subscriptions should receive
111
117
an event based on several factors, which makes the `RequestDeliverParams` struct
112
118
more complicated:
113
119
```cpp
114
- struct RequestDeliverParams
120
+ struct [[nodiscard]] RequestDeliverParams
115
121
{
116
122
// Deliver to subscriptions on this field.
117
123
std::string_view field;
@@ -149,7 +155,7 @@ using SubscriptionArguments = std::map<std::string_view, response::Value>;
149
155
using SubscriptionArgumentFilterCallback = std::function<bool (response::MapType::const_reference)>;
150
156
using SubscriptionDirectiveFilterCallback = std::function<bool (Directives::const_reference)>;
151
157
152
- struct SubscriptionFilter
158
+ struct [[nodiscard]] SubscriptionFilter
153
159
{
154
160
// Optional field argument filter, which can either be a set of required arguments, or a
155
161
// callback which returns true if the arguments match custom criteria.
@@ -180,6 +186,6 @@ that, there's a public `Request::findOperationDefinition` method which returns
180
186
the operation type as a ` std::string_view ` along with a pointer to the AST node
181
187
for the selected operation in the parsed query:
182
188
``` 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;
185
191
```
0 commit comments