From 1d469cdcf3812e90fd3e3087d3aa45523593a29c Mon Sep 17 00:00:00 2001 From: Shane Myrick Date: Fri, 19 Aug 2022 16:03:56 -0700 Subject: [PATCH 1/3] Rename property for RESTDataSource --- CHANGELOG.md | 1 + docs/source/data/data-sources.mdx | 2 +- packages/apollo-datasource-rest/README.md | 2 +- packages/apollo-datasource-rest/src/RESTDataSource.ts | 4 ++-- .../src/__tests__/RESTDataSource.test.ts | 6 +++--- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b7b1905755d..678b569f2e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ The version headers in this history reflect the versions of Apollo Server itself ## vNEXT - [apollo-datasource-rest] Add option to disable GET cache [PR #6650](https://github.com/apollographql/apollo-server/pull/6650) +- [apollo-datasource-rest] Rename property to `memoizeGetRequests` ## v3.10.1 diff --git a/docs/source/data/data-sources.mdx b/docs/source/data/data-sources.mdx index 0a07abceb2d..992876b675e 100644 --- a/docs/source/data/data-sources.mdx +++ b/docs/source/data/data-sources.mdx @@ -163,7 +163,7 @@ class MoviesAPI extends RESTDataSource { constructor() { super(); // Defaults to true - this.requestCacheEnabled = false; + this.memoizeGetRequests = false; } // Outgoing requests are never cached, however the response cache is still enabled diff --git a/packages/apollo-datasource-rest/README.md b/packages/apollo-datasource-rest/README.md index b445f3a42a0..ed2bfba6d99 100644 --- a/packages/apollo-datasource-rest/README.md +++ b/packages/apollo-datasource-rest/README.md @@ -80,7 +80,7 @@ class MoviesAPI extends RESTDataSource { constructor() { super(); // Defaults to true - this.requestCacheEnabled = false; + this.memoizeGetRequests = false; } // Outgoing requests are never cached, however the response cache is still enabled diff --git a/packages/apollo-datasource-rest/src/RESTDataSource.ts b/packages/apollo-datasource-rest/src/RESTDataSource.ts index 52be06c8b6a..79a35896807 100644 --- a/packages/apollo-datasource-rest/src/RESTDataSource.ts +++ b/packages/apollo-datasource-rest/src/RESTDataSource.ts @@ -50,7 +50,7 @@ export abstract class RESTDataSource extends DataSource { context!: TContext; memoizedResults = new Map>(); baseURL?: string; - requestCacheEnabled: boolean = true; + memoizeGetRequests: boolean = true; constructor(private httpFetch?: typeof fetch) { super(); @@ -268,7 +268,7 @@ export abstract class RESTDataSource extends DataSource { // Cache GET requests based on the calculated cache key // Disabling the request cache does not disable the response cache - if (this.requestCacheEnabled) { + if (this.memoizeGetRequests) { if (request.method === 'GET') { let promise = this.memoizedResults.get(cacheKey); if (promise) return promise; diff --git a/packages/apollo-datasource-rest/src/__tests__/RESTDataSource.test.ts b/packages/apollo-datasource-rest/src/__tests__/RESTDataSource.test.ts index d9053b0b31d..963d9bb6dc5 100644 --- a/packages/apollo-datasource-rest/src/__tests__/RESTDataSource.test.ts +++ b/packages/apollo-datasource-rest/src/__tests__/RESTDataSource.test.ts @@ -639,7 +639,7 @@ describe('RESTDataSource', () => { it('allows disabling the GET cache', async () => { const dataSource = new (class extends RESTDataSource { override baseURL = 'https://api.example.com'; - override requestCacheEnabled = false; + override memoizeGetRequests = false; getFoo(id: number) { return this.get(`foo/${id}`); @@ -808,7 +808,7 @@ describe('RESTDataSource', () => { it('allows setting cache options for each request', async () => { const dataSource = new (class extends RESTDataSource { override baseURL = 'https://api.example.com'; - override requestCacheEnabled = false; + override memoizeGetRequests = false; getFoo(id: number) { return this.get(`foo/${id}`); @@ -837,7 +837,7 @@ describe('RESTDataSource', () => { it('allows setting a short TTL for the cache', async () => { const dataSource = new (class extends RESTDataSource { override baseURL = 'https://api.example.com'; - override requestCacheEnabled = false; + override memoizeGetRequests = false; getFoo(id: number) { return this.get(`foo/${id}`); From 480b65e5ac53bef61fab9a2b255d6082d7098b56 Mon Sep 17 00:00:00 2001 From: Shane Myrick Date: Fri, 19 Aug 2022 16:05:25 -0700 Subject: [PATCH 2/3] Update docs with rename --- docs/source/data/data-sources.mdx | 6 +++--- packages/apollo-datasource-rest/README.md | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/source/data/data-sources.mdx b/docs/source/data/data-sources.mdx index 992876b675e..ae14f952baa 100644 --- a/docs/source/data/data-sources.mdx +++ b/docs/source/data/data-sources.mdx @@ -152,13 +152,13 @@ class MoviesAPI extends RESTDataSource { } ``` -##### `requestCacheEnabled` +##### `memoizeGetRequests` By default, `RESTDataSource` caches all outgoing GET **requests** in a separate memoized cache from the regular response cache. It makes the assumption that all responses from HTTP GET calls are cacheable by their URL. If a request is made with the same cache key (URL by default) but with an HTTP method other than GET, the cached request is then cleared. -If you would like to disable the GET request cache, set the `requestCacheEnabled` property to `false`. You might want to do this if your API is not actually cacheable or your data changes over time. +If you would like to disable the GET request cache, set the `memoizeGetRequests` property to `false`. You might want to do this if your API is not actually cacheable or your data changes over time. -```js title="requestCacheEnabled.js" +```js title="memoizeGetRequests.js" class MoviesAPI extends RESTDataSource { constructor() { super(); diff --git a/packages/apollo-datasource-rest/README.md b/packages/apollo-datasource-rest/README.md index ed2bfba6d99..79af2c934fb 100644 --- a/packages/apollo-datasource-rest/README.md +++ b/packages/apollo-datasource-rest/README.md @@ -69,13 +69,13 @@ class MoviesAPI extends RESTDataSource { } ``` -#### `requestCacheEnabled` +#### `memoizeGetRequests` By default, `RESTDataSource` caches all outgoing GET **requests** in a separate memoized cache from the regular response cache. It makes the assumption that all responses from HTTP GET calls are cacheable by their URL. If a request is made with the same cache key (URL by default) but with an HTTP method other than GET, the cached request is then cleared. -If you would like to disable the GET request cache, set the `requestCacheEnabled` property to `false`. You might want to do this if your API is not actually cacheable or your data changes over time. +If you would like to disable the GET request cache, set the `memoizeGetRequests` property to `false`. You might want to do this if your API is not actually cacheable or your data changes over time. -```js title="requestCacheEnabled.js" +```js title="memoizeGetRequests.js" class MoviesAPI extends RESTDataSource { constructor() { super(); From 4671b57de2d64007b48a42830048ce4addad2a16 Mon Sep 17 00:00:00 2001 From: Shane Myrick Date: Fri, 19 Aug 2022 16:13:04 -0700 Subject: [PATCH 3/3] Revert newline in changelog --- CHANGELOG.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 678b569f2e6..4822c88d138 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,8 +10,7 @@ The version headers in this history reflect the versions of Apollo Server itself ## vNEXT -- [apollo-datasource-rest] Add option to disable GET cache [PR #6650](https://github.com/apollographql/apollo-server/pull/6650) -- [apollo-datasource-rest] Rename property to `memoizeGetRequests` +- [apollo-datasource-rest] Add option to disable GET cache [PR #6650](https://github.com/apollographql/apollo-server/pull/6650) and [PR #6834](https://github.com/apollographql/apollo-server/pull/6834) ## v3.10.1