From 8cc8437d011800aac1b6e79d4561bc6019186bfe Mon Sep 17 00:00:00 2001 From: Shane Myrick Date: Fri, 19 Aug 2022 16:29:42 -0700 Subject: [PATCH] Rename property for RESTDataSource (#6834) --- CHANGELOG.md | 2 +- docs/source/data/data-sources.mdx | 8 ++++---- packages/apollo-datasource-rest/README.md | 8 ++++---- packages/apollo-datasource-rest/src/RESTDataSource.ts | 4 ++-- .../src/__tests__/RESTDataSource.test.ts | 6 +++--- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b7b1905755d..4822c88d138 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +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] 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 diff --git a/docs/source/data/data-sources.mdx b/docs/source/data/data-sources.mdx index 0a07abceb2d..ae14f952baa 100644 --- a/docs/source/data/data-sources.mdx +++ b/docs/source/data/data-sources.mdx @@ -152,18 +152,18 @@ 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(); // 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..79af2c934fb 100644 --- a/packages/apollo-datasource-rest/README.md +++ b/packages/apollo-datasource-rest/README.md @@ -69,18 +69,18 @@ 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(); // 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}`);