@@ -164,7 +164,7 @@ ExecuteMutation(mutation, schema, variableValues, initialValue):
164
164
165
165
### Subscription
166
166
167
- If the operation is a subscription, the result is an event stream called the
167
+ If the operation is a subscription, the result is an _ event stream _ called the
168
168
"Response Stream" where each event in the event stream is the result of
169
169
executing the operation for each new event on an underlying "Source Stream".
170
170
@@ -217,14 +217,21 @@ chat room ID is the "topic" and each "publish" contains the sender and text.
217
217
218
218
** Event Streams**
219
219
220
- An event stream represents a sequence of discrete events over time which can be
221
- observed. As an example, a "Pub-Sub" system may produce an event stream when
222
- "subscribing to a topic", with an event occurring on that event stream for each
223
- "publish" to that topic. Event streams may produce an infinite sequence of
224
- events or may complete at any point. Event streams may complete in response to
225
- an error or simply because no more events will occur. An observer may at any
226
- point decide to stop observing an event stream by cancelling it, after which it
227
- must receive no more events from that event stream.
220
+ :: An _ event stream_ represents a sequence of events: discrete emitted values
221
+ over time which can be observed. As an example, a "Pub-Sub" system may produce
222
+ an _ event stream_ when "subscribing to a topic", with an value emitted for each
223
+ "publish" to that topic.
224
+
225
+ An _ event stream_ may complete at any point, often because no further events
226
+ will occur. An _ event stream_ may emit an infinite sequence of values, in which
227
+ it may never complete. If an _ event stream_ encounters an error, it must
228
+ complete with that error.
229
+
230
+ An observer may at any point decide to stop observing an _ event stream_ by
231
+ cancelling it. When an _ event stream_ is cancelled, it must complete.
232
+
233
+ Internal user code also may cancel an _ event stream_ for any reason, which would
234
+ be observed as that _ event stream_ completing.
228
235
229
236
** Supporting Subscriptions at Scale**
230
237
@@ -250,8 +257,8 @@ service details should be chosen by the implementing service.
250
257
251
258
#### Source Stream
252
259
253
- A Source Stream represents the sequence of events, each of which will trigger a
254
- GraphQL execution corresponding to that event . Like field value resolution, the
260
+ A Source Stream is an _ event stream _ representing a sequence of root values,
261
+ each of which will trigger a GraphQL execution . Like field value resolution, the
255
262
logic to create a Source Stream is application-specific.
256
263
257
264
CreateSourceEventStream(subscription, schema, variableValues, initialValue):
@@ -268,15 +275,15 @@ CreateSourceEventStream(subscription, schema, variableValues, initialValue):
268
275
- Let {field} be the first entry in {fields}.
269
276
- Let {argumentValues} be the result of {CoerceArgumentValues(subscriptionType,
270
277
field, variableValues)}.
271
- - Let {fieldStream } be the result of running
278
+ - Let {sourceStream } be the result of running
272
279
{ResolveFieldEventStream(subscriptionType, initialValue, fieldName,
273
280
argumentValues)}.
274
- - Return {fieldStream }.
281
+ - Return {sourceStream }.
275
282
276
283
ResolveFieldEventStream(subscriptionType, rootValue, fieldName, argumentValues):
277
284
278
285
- Let {resolver} be the internal function provided by {subscriptionType} for
279
- determining the resolved event stream of a subscription field named
286
+ determining the resolved _ event stream _ of a subscription field named
280
287
{fieldName}.
281
288
- Return the result of calling {resolver}, providing {rootValue} and
282
289
{argumentValues}.
@@ -287,17 +294,33 @@ operation type.
287
294
288
295
#### Response Stream
289
296
290
- Each event in the underlying Source Stream triggers execution of the
291
- subscription _ selection set_ using that event as a root value .
297
+ Each event from the underlying Source Stream triggers execution of the
298
+ subscription _ selection set_ using that event's value as the {initialValue} .
292
299
293
300
MapSourceToResponseEvent(sourceStream, subscription, schema, variableValues):
294
301
295
- - Return a new event stream {responseStream} which yields events as follows:
296
- - For each {event} on {sourceStream}:
297
- - Let {response} be the result of running
298
- {ExecuteSubscriptionEvent(subscription, schema, variableValues, event)}.
299
- - Yield an event containing {response}.
300
- - When {sourceStream} completes: complete {responseStream}.
302
+ - Let {responseStream} be a new _ event stream_ .
303
+ - When {sourceStream} emits {sourceValue}:
304
+ - Let {response} be the result of running
305
+ {ExecuteSubscriptionEvent(subscription, schema, variableValues,
306
+ sourceValue)}.
307
+ - If internal {error} was raised:
308
+ - Cancel {sourceStream}.
309
+ - Complete {responseStream} with {error}.
310
+ - Otherwise emit {response} on {responseStream}.
311
+ - When {sourceStream} completes normally:
312
+ - Complete {responseStream} normally.
313
+ - When {sourceStream} completes with {error}:
314
+ - Complete {responseStream} with {error}.
315
+ - When {responseStream} is cancelled:
316
+ - Cancel {sourceStream}.
317
+ - Complete {responseStream} normally.
318
+ - Return {responseStream}.
319
+
320
+ Note: Since {ExecuteSubscriptionEvent()} handles all _ field error_ , and _ request
321
+ error_ only occur during {CreateSourceEventStream()}, the only remaining error
322
+ condition handled from {ExecuteSubscriptionEvent()} are internal exceptional
323
+ errors not described by this specification.
301
324
302
325
ExecuteSubscriptionEvent(subscription, schema, variableValues, initialValue):
303
326
@@ -317,9 +340,9 @@ Note: The {ExecuteSubscriptionEvent()} algorithm is intentionally similar to
317
340
#### Unsubscribe
318
341
319
342
Unsubscribe cancels the Response Stream when a client no longer wishes to
320
- receive payloads for a subscription. This may in turn also cancel the Source
321
- Stream. This is also a good opportunity to clean up any other resources used by
322
- the subscription.
343
+ receive payloads for a subscription. This in turn also cancels the Source
344
+ Stream, which is a good opportunity to clean up any other resources used by the
345
+ subscription.
323
346
324
347
Unsubscribe(responseStream):
325
348
0 commit comments