Skip to content

feat(subscriptions): added code comments #858

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ export type {
ExecutionResult,
} from './execution';

export { subscribe, createSubscriptionSourceEventStream } from './subscription';
export { subscribe, createSourceEventStream } from './subscription';

// Validate GraphQL queries.
export {
Expand Down
2 changes: 1 addition & 1 deletion src/subscription/index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { subscribe, createSubscriptionSourceEventStream } from './subscribe';
export { subscribe, createSourceEventStream } from './subscribe';
18 changes: 15 additions & 3 deletions src/subscription/subscribe.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,16 @@ import type {
OperationDefinitionNode,
} from '../language/ast';

export function createSubscriptionSourceEventStream(
/**
* Implements the "CreateSourceEventStream" algorithm described in the
* GraphQL specification, resolving the subscription source event stream.
*
* Returns an AsyncIterable
*
* A Source Stream represents the sequence of events, each of which is
* expected to be used to trigger a GraphQL execution for that event.
*/
export function createSourceEventStream(
schema: GraphQLSchema,
document: DocumentNode,
rootValue?: mixed,
Expand Down Expand Up @@ -63,7 +72,7 @@ export function createSubscriptionSourceEventStream(
}

/**
* Implements the "Subscribing to request" section of the GraphQL specification.
* Implements the "Subscribe" algorithm described in the GraphQL specification.
*
* Returns an AsyncIterator
*
Expand All @@ -78,7 +87,7 @@ export function subscribe(
variableValues?: ?{[key: string]: mixed},
operationName?: ?string,
): AsyncIterator<ExecutionResult> {
const subscription = createSubscriptionSourceEventStream(
const subscription = createSourceEventStream(
schema,
document,
rootValue,
Expand Down Expand Up @@ -138,6 +147,9 @@ function resolveSubscription(
addPath(undefined, responseName)
);

// resolveFieldValueOrError implements the "ResolveFieldEventStream"
// algorithm from GraphQL specification. It differs from
// "ResolveFieldValue" due to providing a different `resolveFn`.
const subscription = resolveFieldValueOrError(
exeContext,
fieldDef,
Expand Down