@@ -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,18 +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 emitted events over time which
221
- can be observed. As an example, a "Pub-Sub" system may produce an event stream
222
- when "subscribing to a topic", with an event emitted for each "publish" to that
223
- topic.
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
224
225
- Event streams may complete at any point, often because no further events will
226
- occur. Event streams may emit an infinite sequence of events , in which they may
227
- never complete. If an event stream encounters an error, it must complete with
228
- that error.
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
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.
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.
232
235
233
236
** Supporting Subscriptions at Scale**
234
237
@@ -254,8 +257,8 @@ service details should be chosen by the implementing service.
254
257
255
258
#### Source Stream
256
259
257
- A Source Stream represents the sequence of events, each of which will trigger a
258
- 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
259
262
logic to create a Source Stream is application-specific.
260
263
261
264
CreateSourceEventStream(subscription, schema, variableValues, initialValue):
@@ -280,7 +283,7 @@ CreateSourceEventStream(subscription, schema, variableValues, initialValue):
280
283
ResolveFieldEventStream(subscriptionType, rootValue, fieldName, argumentValues):
281
284
282
285
- Let {resolver} be the internal function provided by {subscriptionType} for
283
- determining the resolved event stream of a subscription field named
286
+ determining the resolved _ event stream _ of a subscription field named
284
287
{fieldName}.
285
288
- Return the result of calling {resolver}, providing {rootValue} and
286
289
{argumentValues}.
@@ -291,24 +294,34 @@ operation type.
291
294
292
295
#### Response Stream
293
296
294
- Each event in the underlying Source Stream triggers execution of the
295
- 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} .
296
299
297
300
MapSourceToResponseEvent(sourceStream, subscription, schema, variableValues):
298
301
299
- - Let {responseStream} be a new event stream .
300
- - When {sourceStream} emits {event }:
302
+ - Let {responseStream} be a new _ event stream _ .
303
+ - When {sourceStream} emits {sourceValue }:
301
304
- Let {response} be the result of running
302
- {ExecuteSubscriptionEvent(subscription, schema, variableValues, event)}.
303
- - Emit {response} on {responseStream}.
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}.
304
311
- When {sourceStream} completes normally:
305
312
- Complete {responseStream} normally.
306
313
- When {sourceStream} completes with {error}:
307
314
- Complete {responseStream} with {error}.
308
315
- When {responseStream} is cancelled:
309
316
- Cancel {sourceStream}.
317
+ - Complete {responseStream} normally.
310
318
- Return {responseStream}.
311
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.
324
+
312
325
ExecuteSubscriptionEvent(subscription, schema, variableValues, initialValue):
313
326
314
327
- Let {subscriptionType} be the root Subscription type in {schema}.
0 commit comments