diff --git a/docs/source/index.md b/docs/source/index.md index 44815bec3..f414e3928 100644 --- a/docs/source/index.md +++ b/docs/source/index.md @@ -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 diff --git a/docs/source/lifecycle-events.md b/docs/source/lifecycle-events.md index 93dbcbd58..e25009fc3 100644 --- a/docs/source/lifecycle-events.md +++ b/docs/source/lifecycle-events.md @@ -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 diff --git a/docs/source/subscriptions-to-schema.md b/docs/source/subscriptions-to-schema.md index 865844ff2..db574f1e5 100644 --- a/docs/source/subscriptions-to-schema.md +++ b/docs/source/subscriptions-to-schema.md @@ -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!' }}) -``` \ No newline at end of file +``` + +

Payload Transformation

+ +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') + } + }, +}; +```