Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

Commit

Permalink
docs(subscriptions): updated subscriptions docs
Browse files Browse the repository at this point in the history
  • Loading branch information
dotansimha committed May 19, 2017
1 parent 99cbcff commit 5b2a57e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/source/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ The process of setting up a GraphQL subscriptions server consist of the followin

1. Declaring subscriptions in the GraphQL schema
2. Setup a PubSub instance that our server will publish new events to
3. Hook together `PubSub` evnet and GraphQL subscription.
3. Hook together `PubSub` event and GraphQL subscription.
4. Setting up `SubscriptionsServer`, a transport between the server and the clients

2 changes: 1 addition & 1 deletion docs/source/lifecycle-events.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ order: 404

* `onConnect` - called upon client connection, with the `connectionParams` passed to `SubscriptionsClient` - you can return a Promise and reject the connection by throwing an exception. The resolved return value will be appended to the GraphQL `context` of your subscriptions.
* `onDisconnect` - called when the client disconnects.
* `onOperation` - called when the client executes a GraphQL operation - use this method to create custom params that will be used when resolving the operarion.
* `onOperation` - called when the client executes a GraphQL operation - use this method to create custom params that will be used when resolving the operation.
* `onOperationDone` - called when client's operation has been done it's execution (for subscriptions called when unsubscribe, and for query/mutation called immediatly).

```js
Expand Down
24 changes: 23 additions & 1 deletion docs/source/subscriptions-to-schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,26 @@ Then, later on your code, you can publish data to your topic by using `pubsub.pu

```js
pubsub.publish('commentAdded', { commentAdded: { id: 1, content: 'Hello!' }})
```
```

<h2 id="subscription-server">Payload Transformation</h2>

When using `subscribe` field, it's also possible to manipulate the event payload before running it throught the GraphQL execution engine.

Add `resolve` method near your `subscribe` and change the payload as you wish:


```js
const rootResolver = {
Subscription: {
commentAdded: {
resolve: (payload) => {
return {
customData: payload,
};
},
subscribe: () => pubsub.asyncIterator('commentAdded')
}
},
};
```

0 comments on commit 5b2a57e

Please sign in to comment.