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
+132Lines changed: 132 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -826,6 +826,138 @@ 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
+
### `instrumentation`
830
+
831
+
An optional `instrumentation` instance can be present in the plugin.
832
+
833
+
This `Instrumentation` instance allows to wrap an entire phase execution (including all plugin
834
+
hooks), meaning running code just before, just after and around the execution of the phase.
835
+
836
+
Instrumentation doesn't have access to input/output of a phase, use hooks to have access to those
837
+
data. If needed, we recommend to share data between instrumentation and hooks with a `WeakMap` and
838
+
the given `context` as the key.
839
+
840
+
All instrumentation takes 2 parameters:
841
+
842
+
-`payload`: an object containing the graphql `context`, http `request`, or the subgraph
843
+
`executionRequest` depending on the 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
+
#### Instrumentation composition
850
+
851
+
If multiple plugins have `instrumentation`, 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
+
instrumentation to have a different oreder of execution).
0 commit comments