From 35f37588e5ec721992548bfd69622b01857d6cd7 Mon Sep 17 00:00:00 2001 From: Lenny Burdette Date: Tue, 3 Jan 2023 11:53:18 -0500 Subject: [PATCH] docs: demo `contextValue` in `executeOperation` (#7270) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Show an example of providing `contextValue` to `executeOperation` Co-authored-by: Trevor Scheer --- docs/source/api/apollo-server.mdx | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/source/api/apollo-server.mdx b/docs/source/api/apollo-server.mdx index 1063da21cb8..a5b9a203f03 100644 --- a/docs/source/api/apollo-server.mdx +++ b/docs/source/api/apollo-server.mdx @@ -581,6 +581,15 @@ The `executeOperation` method takes two arguments: - The first argument is an object describing the GraphQL operation to be executed. - Supported fields are listed in the table below. - The second argument is the optional options object. This object includes the operation's optional [`contextValue`](../data/context#the-contextvalue-object). This argument is only optional if your server _doesn't_ expect a context value (i.e., your server uses the default context because you didn't explicitly provide another one). + +```js +const response = await server.executeOperation({ + query: 'query SayHelloWorld($name: String) { hello(name: $name) }', + variables: { name: 'world' }, +}, { + contextValue: { userId: 'test' }, +}); +``` The `response` object returned from `executeOperation` is a `GraphQLResponse`, which has `body` and `http` fields.