Skip to content

Commit

Permalink
Add docs and examples for plugin end hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
nwalters512 authored and abernix committed Dec 30, 2019
1 parent 81529d9 commit 7da104c
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions docs/source/integrations/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,54 @@ defines functions that respond to request lifecycle events. This structure
organizes and encapsulates all of your plugin's request lifecycle logic, making it
easier to reason about.

The following request lifecycle event handlers can optionally return a function
that will be invoked after the lifecycle phase is complete:

* [`parsingDidStart`](#parsingdidstart)
* [`validationDidStart`](#validationdidstart)
* [`executionDidStart`](#executiondidstart)

These "end hooks" will be invoked with any error(s) that occurred during the
execution of that lifecycle phase. For example, the following plugin will log
any errors that occur during any of the above lifecycle events:

```js
const myPlugin = {
requestDidStart() {
return {
parsingDidStart() {
return (err) => {
if (err) {
console.error(err);
}
}
},
validationDidStart() {
// This end hook is unique in that it can receive an array of errors,
// which will contain every validation error that occurred
return (errs) => {
if (errs) {
errs.forEach(err => console.error(err));
}
}
},
executionDidStart() {
return (err) => {
if (err) {
console.error(err);
}
}
}
}
}
}
```

Note that the `validationDidStart` end hook receives an array of errors, which
will contain every validation error that occurred, if any. The arguments to each
end hook are documented in the type definitions in the [request lifecycle events
docs](#request-lifecycle-events) below.

### Inspecting request and response details

As the example above shows, `requestDidStart` and request lifecycle functions accept a `requestContext`
Expand Down

0 comments on commit 7da104c

Please sign in to comment.