Repository: apollographql/apollo-server
Pull request #7373 (2023-02-10 18:41:07)

[docs] Add docs on how to set a REST timeout
The docs for `@apollo/datasource-rest` are missing info about how to set a timeout. While this feature is not directly handled by the Apollo package and instead is really information about how to use the `fetch()` API, we can add this common use case here and link off to MDN for more info.

netlify[bot]: ### <span aria-hidden="true">👷</span> Deploy Preview for *apollo-server-docs* processing.


|  Name | Link |
|:-:|------------------------|
|<span aria-hidden="true">🔨</span> Latest commit | 0c4126efb9ae6475cfa9804eaea0fc9101b8eae9 |
|<span aria-hidden="true">🔍</span> Latest deploy log | https://app.netlify.com/sites/apollo-server-docs/deploys/63e68fc68d135b0008d11d8d |
codesandbox-ci[bot]: This pull request is automatically built and testable in [CodeSandbox](https://codesandbox.io).

  To see build info of the built libraries, click [here](https://ci.codesandbox.io/status/apollographql/apollo-server/pr/7373/builds/345407) or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 0c4126efb9ae6475cfa9804eaea0fc9101b8eae9:

|Sandbox| Source |
|--|--|
|[Apollo Server Typescript](https://codesandbox.io/s/apollo-server-typescript-dlv6x5)| Configuration |
|[Apollo Server](https://codesandbox.io/s/apollo-server-8f7o9q)| Configuration |

smyrick: cc @StephenBarlow for docs review

Patch:
diff --git a/.changeset/tasty-bugs-smoke.md b/.changeset/tasty-bugs-smoke.md
new file mode 100644
index 000000000..7105d60d3
--- /dev/null
+++ b/.changeset/tasty-bugs-smoke.md
@@ -0,0 +1,5 @@
+---
+'@apollo/server-integration-testsuite': patch
+---
+
+Update graphql-http dependency
diff --git a/docs/source/data/fetching-rest.mdx b/docs/source/data/fetching-rest.mdx
index f2dc5c35e..a57256ba0 100644
--- a/docs/source/data/fetching-rest.mdx
+++ b/docs/source/data/fetching-rest.mdx
@@ -45,7 +45,7 @@ import { RESTDataSource } from '@apollo/datasource-rest';
 class MoviesAPI extends RESTDataSource {
   override baseURL = 'https://movies-api.example.com/';
 
-  async getMovie(id): Promise<Movie> {
+  async getMovie(id: string): Promise<Movie> {
     return this.get<Movie>(`movies/${encodeURIComponent(id)}`);
   }
 
@@ -246,7 +246,7 @@ class MoviesAPI extends RESTDataSource {
 
 </MultiCodeBlock>
 
-### Requests specifying TTL
+### Specifying cache TTL
 
 > 📣 **New in Apollo Server 4**: Apollo Server no longer automatically provides its cache to data sources. [See here for more details](../migration/#datasources).
 
@@ -385,6 +385,24 @@ class MoviesAPI extends RESTDataSource {
 }
 ```
 
+## Setting fetch options
+The second parameter passed to each REST method is an object containing request options. These include options commonly passed to [`fetch`](https://developer.mozilla.org/en-US/docs/Web/API/fetch#syntax), including `method`, `headers`, `body`, and `signal`.
+
+> If you're looking for other advanced options that aren't covered in the Apollo docs, you can set them here and refer to your Fetch API docs.
+
+```
+this.get('/movies/1', options);
+```
+
+### Setting timeouts
+To set a `fetch` timeout, provide an [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) via the `signal` option, which enables you to abort the request with custom logic.
+
+Here's an example of a simple timeout after a fixed time for every request:
+
+```
+this.get('/movies/1', { signal: AbortSignal.timeout(myTimeoutMilliseconds) });
+```
+
 ## Intercepting fetches
 
 > **New in Apollo Server 4**: Apollo Server 4 now uses the [`@apollo/utils.fetcher`](../migration#apolloutilsfetcher-replaces-apollo-server-env) interface under the hood for fetching. This interface lets you choose your own implementation of the Fetch API. To ensure compatibility with all Fetch implementations, the request provided to hooks like `willSendRequest` is a plain JS object rather than a `Request` object with methods.
diff --git a/package-lock.json b/package-lock.json
index eb18e9661..36c6b71e1 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -8451,9 +8451,9 @@
       }
     },
     "node_modules/graphql-http": {
-      "version": "1.13.0",
-      "resolved": "https://registry.npmjs.org/graphql-http/-/graphql-http-1.13.0.tgz",
-      "integrity": "sha512-3Ia3ql9k+i/GvjNucwRdqdbumLeyJ8Zame4IhniMy/974t+Dy2mDnF08fOCKwXJwd3ErmzhYS/ZyvcXiX4v8wg==",
+      "version": "1.16.0",
+      "resolved": "https://registry.npmjs.org/graphql-http/-/graphql-http-1.16.0.tgz",
+      "integrity": "sha512-kgYFSCgTcvakPCobidCw5G4x9maDaOWmbSozt9g2nkqcUhf+FIDcLv+nL8asBDvas8rRJvoRoLkQYNC1AZfZDw==",
       "engines": {
         "node": ">=12"
       },
@@ -14287,12 +14287,12 @@
     },
     "packages/integration-testsuite": {
       "name": "@apollo/server-integration-testsuite",
-      "version": "4.3.3",
+      "version": "4.4.0",
       "license": "MIT",
       "dependencies": {
         "@apollo/cache-control-types": "^1.0.2",
         "@apollo/client": "^3.6.9",
-        "@apollo/server": "4.3.3",
+        "@apollo/server": "4.4.0",
         "@apollo/server-plugin-landing-page-graphql-playground": "^4.0.0",
         "@apollo/usage-reporting-protobuf": "^4.0.0",
         "@apollo/utils.createhash": "^2.0.0",
@@ -14300,7 +14300,7 @@
         "@josephg/resolvable": "^1.0.1",
         "body-parser": "^1.20.0",
         "express": "^4.18.1",
-        "graphql-http": "1.13.0",
+        "graphql-http": "1.16.0",
         "graphql-tag": "^2.12.6",
         "loglevel": "^1.8.0",
         "node-fetch": "^2.6.7",
@@ -14373,7 +14373,7 @@
     },
     "packages/server": {
       "name": "@apollo/server",
-      "version": "4.3.3",
+      "version": "4.4.0",
       "license": "MIT",
       "dependencies": {
         "@apollo/cache-control-types": "^1.0.2",
@@ -14741,7 +14741,7 @@
       "requires": {
         "@apollo/cache-control-types": "^1.0.2",
         "@apollo/client": "^3.6.9",
-        "@apollo/server": "4.3.3",
+        "@apollo/server": "4.4.0",
         "@apollo/server-plugin-landing-page-graphql-playground": "^4.0.0",
         "@apollo/usage-reporting-protobuf": "^4.0.0",
         "@apollo/utils.createhash": "^2.0.0",
@@ -14749,7 +14749,7 @@
         "@josephg/resolvable": "^1.0.1",
         "body-parser": "^1.20.0",
         "express": "^4.18.1",
-        "graphql-http": "1.13.0",
+        "graphql-http": "1.16.0",
         "graphql-tag": "^2.12.6",
         "loglevel": "^1.8.0",
         "node-fetch": "^2.6.7",
@@ -21005,9 +21005,9 @@
       }
     },
     "graphql-http": {
-      "version": "1.13.0",
-      "resolved": "https://registry.npmjs.org/graphql-http/-/graphql-http-1.13.0.tgz",
-      "integrity": "sha512-3Ia3ql9k+i/GvjNucwRdqdbumLeyJ8Zame4IhniMy/974t+Dy2mDnF08fOCKwXJwd3ErmzhYS/ZyvcXiX4v8wg==",
+      "version": "1.16.0",
+      "resolved": "https://registry.npmjs.org/graphql-http/-/graphql-http-1.16.0.tgz",
+      "integrity": "sha512-kgYFSCgTcvakPCobidCw5G4x9maDaOWmbSozt9g2nkqcUhf+FIDcLv+nL8asBDvas8rRJvoRoLkQYNC1AZfZDw==",
       "requires": {}
     },
     "graphql-request": {
diff --git a/packages/server/CHANGELOG.md b/packages/server/CHANGELOG.md
index 29153e2aa..0cc384b01 100644
--- a/packages/server/CHANGELOG.md
+++ b/packages/server/CHANGELOG.md
@@ -1,5 +1,11 @@
 # @apollo/server
 
+## 4.4.0
+
+### Minor Changes
+
+- [#7358](https://github.com/apollographql/apollo-server/pull/7358) [`f2d433b4f`](https://github.com/apollographql/apollo-server/commit/f2d433b4f5c92b1a56816c55a8bda2b1e338beeb) Thanks [@esilverm](https://github.com/esilverm)! - Show "Include Cookies" toggle in Embedded Sandbox landing page.
+
 ## 4.3.3
 
 ### Patch Changes
diff --git a/packages/server/package.json b/packages/server/package.json
index 5cb4b2cc8..cd61e3206 100644
--- a/packages/server/package.json
+++ b/packages/server/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@apollo/server",
-  "version": "4.3.3",
+  "version": "4.4.0",
   "description": "Core engine for Apollo GraphQL server",
   "type": "module",
   "main": "dist/cjs/index.js",
diff --git a/packages/server/src/plugin/landingPage/default/getEmbeddedHTML.ts b/packages/server/src/plugin/landingPage/default/getEmbeddedHTML.ts
index c9e894f03..c17323eae 100644
--- a/packages/server/src/plugin/landingPage/default/getEmbeddedHTML.ts
+++ b/packages/server/src/plugin/landingPage/default/getEmbeddedHTML.ts
@@ -42,7 +42,7 @@ export const getEmbeddedExplorerHTML = (
 
     endpointUrl: string;
 
-    includeCookies?: boolean; // defaults to 'false'
+    hideCookieToggle?: boolean; // defaults to 'true'
   }
   const productionLandingPageConfigOrDefault = {
     displayOptions: {},
@@ -51,7 +51,7 @@ export const getEmbeddedExplorerHTML = (
   };
   const embeddedExplorerParams: Omit<EmbeddableExplorerOptions, 'endpointUrl'> =
     {
-      ...config,
+      graphRef: config.graphRef,
       target: '#embeddableExplorer',
       initialState: {
         ...config,
@@ -61,6 +61,7 @@ export const getEmbeddedExplorerHTML = (
       },
       persistExplorerState:
         productionLandingPageConfigOrDefault.persistExplorerState,
+      hideCookieToggle: false,
     };
 
   return `
@@ -115,12 +116,13 @@ id="embeddableSandbox"
   new window.EmbeddedSandbox({
     target: '#embeddableSandbox',
     initialEndpoint,
-    includeCookies: ${config.includeCookies ?? 'false'},
     initialState: ${getConfigStringForHtml({
       document: config.document ?? undefined,
       variables: config.variables ?? undefined,
       headers: config.headers ?? undefined,
+      includeCookies: config.includeCookies ?? undefined,
     })},
+    hideCookieToggle: false,
   });
 </script>
 `;
diff --git a/renovate.json5 b/renovate.json5
index 99606b115..0cbe05a8c 100644
--- a/renovate.json5
+++ b/renovate.json5
@@ -33,6 +33,17 @@
       "matchUpdateTypes": ["patch", "minor"],
       "groupSlug": "all-minor-patch",
     },
+    // The testsuite depends directly on the tests in `graphql-http`.
+    // Because of this, updates to `graphql-http` affect the contents of
+    // published packages, require a changeset, and cannot be auto-merged.
+    // So we split it into its own Renovate PRs so that it doesn't block
+    // other upgrades.
+    {
+      groupName: "graphql-http",
+      matchPackageNames: ["graphql-http"],
+      matchPaths: ["packages/integration-testsuite/package.json"],
+      rangeStrategy: "pin",
+    },
     // We want the testsuite to explicitly pin the version of @apollo/server
     // since they are supposed to be in lockstep.
     {


Test patch:
diff --git a/packages/integration-testsuite/CHANGELOG.md b/packages/integration-testsuite/CHANGELOG.md
index 72a00e332..5fcea60d2 100644
--- a/packages/integration-testsuite/CHANGELOG.md
+++ b/packages/integration-testsuite/CHANGELOG.md
@@ -1,5 +1,12 @@
 # @apollo/server-integration-testsuite
 
+## 4.4.0
+
+### Patch Changes
+
+- Updated dependencies [[`f2d433b4f`](https://github.com/apollographql/apollo-server/commit/f2d433b4f5c92b1a56816c55a8bda2b1e338beeb)]:
+  - @apollo/server@4.4.0
+
 ## 4.3.3
 
 ### Patch Changes
diff --git a/packages/integration-testsuite/package.json b/packages/integration-testsuite/package.json
index 18ee35380..ecd42e937 100644
--- a/packages/integration-testsuite/package.json
+++ b/packages/integration-testsuite/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@apollo/server-integration-testsuite",
-  "version": "4.3.3",
+  "version": "4.4.0",
   "description": "Test suite for Apollo Server integrations",
   "main": "dist/index.js",
   "types": "dist/index.d.ts",
@@ -28,7 +28,7 @@
   "dependencies": {
     "@apollo/cache-control-types": "^1.0.2",
     "@apollo/client": "^3.6.9",
-    "@apollo/server": "4.3.3",
+    "@apollo/server": "4.4.0",
     "@apollo/server-plugin-landing-page-graphql-playground": "^4.0.0",
     "@apollo/utils.keyvaluecache": "^2.1.0",
     "@apollo/utils.createhash": "^2.0.0",
@@ -36,7 +36,7 @@
     "@josephg/resolvable": "^1.0.1",
     "body-parser": "^1.20.0",
     "express": "^4.18.1",
-    "graphql-http": "1.13.0",
+    "graphql-http": "1.16.0",
     "graphql-tag": "^2.12.6",
     "loglevel": "^1.8.0",
     "node-fetch": "^2.6.7",
diff --git a/packages/server/src/__tests__/plugin/landingPage/getEmbeddedExplorerHTML.test.ts b/packages/server/src/__tests__/plugin/landingPage/getEmbeddedExplorerHTML.test.ts
index 9b6ecdf6b..72cc4def1 100644
--- a/packages/server/src/__tests__/plugin/landingPage/getEmbeddedExplorerHTML.test.ts
+++ b/packages/server/src/__tests__/plugin/landingPage/getEmbeddedExplorerHTML.test.ts
@@ -51,7 +51,7 @@ describe('Embedded Explorer Landing Page Config HTML', () => {
       </script>
       <script>
         var endpointUrl = window.location.href;
-        var embeddedExplorerConfig = {"includeCookies":true,"document":"query Test { id }","variables":{"option":{"a":"val","b":1,"c":true}},"headers":{"authorization":"true"},"embed":{"displayOptions":{"showHeadersAndEnvVars":true,"docsPanelState":"open","theme":"light"},"persistExplorerState":true},"graphRef":"graph@current","target":"#embeddableExplorer","initialState":{"includeCookies":true,"document":"query Test { id }","variables":{"option":{"a":"val","b":1,"c":true}},"headers":{"authorization":"true"},"embed":{"displayOptions":{"showHeadersAndEnvVars":true,"docsPanelState":"open","theme":"light"},"persistExplorerState":true},"graphRef":"graph@current","displayOptions":{"showHeadersAndEnvVars":true,"docsPanelState":"open","theme":"light"}},"persistExplorerState":true};
+        var embeddedExplorerConfig = {"graphRef":"graph@current","target":"#embeddableExplorer","initialState":{"includeCookies":true,"document":"query Test { id }","variables":{"option":{"a":"val","b":1,"c":true}},"headers":{"authorization":"true"},"embed":{"displayOptions":{"showHeadersAndEnvVars":true,"docsPanelState":"open","theme":"light"},"persistExplorerState":true},"graphRef":"graph@current","displayOptions":{"showHeadersAndEnvVars":true,"docsPanelState":"open","theme":"light"}},"persistExplorerState":true,"hideCookieToggle":false};
         new window.EmbeddedExplorer({
           ...embeddedExplorerConfig,
           endpointUrl,
@@ -89,7 +89,7 @@ describe('Embedded Explorer Landing Page Config HTML', () => {
       </script>
       <script>
         var endpointUrl = window.location.href;
-        var embeddedExplorerConfig = {"includeCookies":false,"embed":true,"graphRef":"graph@current","target":"#embeddableExplorer","initialState":{"includeCookies":false,"embed":true,"graphRef":"graph@current","displayOptions":{}},"persistExplorerState":false};
+        var embeddedExplorerConfig = {"graphRef":"graph@current","target":"#embeddableExplorer","initialState":{"includeCookies":false,"embed":true,"graphRef":"graph@current","displayOptions":{}},"persistExplorerState":false,"hideCookieToggle":false};
         new window.EmbeddedExplorer({
           ...embeddedExplorerConfig,
           endpointUrl,
diff --git a/packages/server/src/__tests__/plugin/landingPage/getEmbeddedSandboxHTML.test.ts b/packages/server/src/__tests__/plugin/landingPage/getEmbeddedSandboxHTML.test.ts
index 0414c1c48..17854abc9 100644
--- a/packages/server/src/__tests__/plugin/landingPage/getEmbeddedSandboxHTML.test.ts
+++ b/packages/server/src/__tests__/plugin/landingPage/getEmbeddedSandboxHTML.test.ts
@@ -45,8 +45,8 @@ describe('Landing Page Config HTML', () => {
         new window.EmbeddedSandbox({
           target: '#embeddableSandbox',
           initialEndpoint,
-          includeCookies: true,
-          initialState: {"document":"query Test { id }","variables":{"option":{"a":"val","b":1,"c":true}},"headers":{"authorization":"true"}},
+          initialState: {"document":"query Test { id }","variables":{"option":{"a":"val","b":1,"c":true}},"headers":{"authorization":"true"},"includeCookies":true},
+          hideCookieToggle: false,
         });
       </script>
     `);
@@ -82,8 +82,8 @@ describe('Landing Page Config HTML', () => {
         new window.EmbeddedSandbox({
           target: '#embeddableSandbox',
           initialEndpoint,
-          includeCookies: false,
-          initialState: {},
+          initialState: {"includeCookies":false},
+          hideCookieToggle: false,
         });
       </script>
     `);