You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/web/docs/src/content/gateway/other-features/custom-plugins.mdx
+117Lines changed: 117 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -826,6 +826,123 @@ Prefer `onRequestParse` when possible, or wrap the hook code in a `try` block.
826
826
|`serverContext`| The final context object that is shared between all hooks and the GraphQL execution. [Learn more about the context](https://the-guild.dev/graphql/yoga-server/docs/features/context#server-context). |
827
827
|`response`| The outgoing HTTP response as WHATWG `Response` object. [Learn more about the response interface](https://developer.mozilla.org/en-US/docs/Web/API/Response). |
828
828
829
+
### `instruments`
830
+
831
+
An optional `instruments` instance can be present in the plugin.
832
+
833
+
This `Instruments` instance allows to wrap an entire phase execution (including all plugin hooks),
834
+
meaning running code just before, just after and around the execution of the phase.
835
+
836
+
Instruments doesn't have access to input/output of a phase, use hooks to have access to those data.
837
+
If needed, we recommend to share data between instruments and hooks with a `WeakMap` and the given
838
+
`context` as the key.
839
+
840
+
All instruments takes 2 parameters:
841
+
842
+
-`payload`: an object containing the graphql context or the http request depending on the
843
+
instrument.
844
+
-`wrapped`: The function representing the execution of the phase. It takes no parameters, and
845
+
returns `void` (or `Promise<void>` for asynchrone phases). **This function must always be
846
+
called**. If this function returns a `Promise`, the instrument should return a `Promise` resolving
847
+
after it.
848
+
849
+
#### Instruments composition
850
+
851
+
If multiple plugins have `instruments`, they are composed in the same order they are defined the
852
+
plugin array (the first is outtermost call, the last is inner most call).
853
+
854
+
It is possible to customize this composition if it doesn't suite your need (ie. you need hooks and
855
+
instruments to have a different oreder of execution).
0 commit comments