Releases: apollographql/datasource-rest
v5.1.1
Patch Changes
- #197 
fcd05faThanks @AaronMoat! - Don't crash when receiving non-string, non-array headers 
v5.1.0
Minor Changes
- 
#186
5ac9b52Thanks @js-lowes! - Customize the logger used byRESTDataSource.
By default theRESTDataSourcewill useconsole.
Common use cases would be to override the default logger withpinoorwinston.E.g.
const pino = require('pino'); const loggerPino = pino({}); const dataSource = new (class extends RESTDataSource {})({ logger: loggerPino, });
In the example above, all logging calls made by the
RESTDataSourcewill now use thepinologger instead of theconsolelogger. 
v5.0.2
Patch Changes
- 
#159
ee018a7Thanks @trevor-scheer! - Updatehttp-cache-semanticspackage to latest patch, resolving a security
issue.Unlike many security updates Apollo repos receive, this is an actual (non-dev)
dependency of this package which means it is actually a user-facing security
issue.The potential impact of this issue is limited to a DOS attack (via an
inefficient regex).This security issue would only affect you if either:
- you pass untrusted (i.e. from your users) 
cache-controlrequest headers - you sending requests to untrusted REST server that might return malicious
cache-controlheaders 
Since
http-cache-semanticsis a careted (^) dependency in this package, the
security issue can (and might already) be resolved via apackage-lock.json
update within your project (possibly triggered bynpm auditor another
dependency update which has already updated its version of the package in
question). Ifnpm ls http-cache-semanticsreveals a tree of dependencies which
only include the4.1.1version (and no references to any previous versions)
then you are currently unaffected and this patch should have (for all intents
and purpose) no effect.More details available here: GHSA-rc47-6667-2j5j
 - you pass untrusted (i.e. from your users) 
 - 
#160
786c44fThanks @trevor-scheer! - Add missing@apollo/utils.withrequiredtype dependency which is part of the
public typings (via theAugmentedRequesttype). - 
#154
bb0cff0Thanks @JustinSomers! - Addresses duplicate content-type header bug due to upper-cased headers being forwarded. This change instead maps all headers to lowercased headers. 
v5.0.1
Patch Changes
- #137 
c9ffa7fThanks @trevor-scheer! - Create intermediate request types (PostRequest, etc.) for consistency and export them.
ExportDataSourceRequest,DataSourceConfig, andDataSourceFetchResulttypes. 
v5.0.0
Version 5 of RESTDataSource addresses many of the long-standing issues and PRs that have existed in this repository (and its former location in the apollo-server repository). While this version does include a number of breaking changes, our hope is that the updated API makes this package more usable and its caching-related behavior less surprising.
The entries below enumerate all of the changes in v5 in detail along with their associated PRs. If you are migrating from v3 or v4, we recommend at least skimming the entries below to see if you're affected by the breaking changes. As always, we recommend using TypeScript with our libraries. This will be especially helpful in surfacing changes to the API which affect your usage. Even if you don't use TypeScript, you can still benefit from the typings we provide using various convenience tools like // @ts-check (with compatible editors like VS Code).
TL;DR
At a higher level, the most notable changes include:
Breaking
- Remove magic around request deduplication behavior and provide a hook to configure its behavior. Previously, requests were deduplicated forever by default. Now, only requests happening concurrently will be deduplicated (and subsequently cleared from the in-memory cache).
 - Cache keys now include the request method by default (no more overlap in GET and POST requests).
 - Remove the semantically confusing 
didReceiveResponsehook. - Paths now behave as links would in a web browser, allowing path segments to contain colons.
 
Additive
- Introduce a public 
fetchmethod, giving access to the fullResponseobject - Improve ETag header semantics (correctly handle 
Last-Modifiedheader) - Introduce a public 
headclass method for issuingHEADrequests 
Major Changes
- 
#100
2e51657Thanks @glasser! - Instead of memoizing GET requests forever in memory, only apply de-duplication during the lifetime of the original request. Replace thememoizeGetRequestsfield with arequestDeduplicationPolicyFor()method to determine how de-duplication works per request.To restore the surprising infinite-unconditional-cache behavior of previous versions, use this implementation of
requestDeduplicationPolicyFor()(which replacesdeduplicate-during-request-lifetimewithdeduplicate-until-invalidated):override protected requestDeduplicationPolicyFor( url: URL, request: RequestOptions, ): RequestDeduplicationPolicy { const cacheKey = this.cacheKeyFor(url, request); if (request.method === 'GET') { return { policy: 'deduplicate-until-invalidated', deduplicationKey: `${request.method} ${cacheKey}`, }; } else { return { policy: 'do-not-deduplicate', invalidateDeduplicationKeys: [`GET ${cacheKey}`], }; } }
To restore the behavior of
memoizeGetRequests = false, use this implementation ofrequestDeduplicationPolicyFor():protected override requestDeduplicationPolicyFor() { return { policy: 'do-not-deduplicate' } as const; }
 - 
#89
4a249ecThanks @trevor-scheer! - This change restores the full functionality ofwillSendRequestwhich
previously existed in the v3 version of this package. The v4 change introduced a
regression where the incoming request'sbodywas no longer included in the
object passed to thewillSendRequesthook, it was alwaysundefined.For consistency and typings reasons, the
pathargument is now the first
argument to thewillSendRequesthook, followed by theAugmentedRequest
request object. - 
#115
be4371fThanks @glasser! - TheerrorFromResponsemethod now receives an options object withurl,request,response, andparsedBodyrather than just a response, and the body has already been parsed. - 
#110
ea43a27Thanks @trevor-scheer! - Update defaultcacheKeyForto include methodIn its previous form,
cacheKeyForonly used the URL to calculate the cache key. As a result, whencacheOptions.ttlwas specified, the method was ignored. This could lead to surprising behavior where a POST request's response was cached and returned for a GET request (for example).The default
cacheKeyFornow includes the request method, meaning there will now be distinct cache entries for a given URL per method. - 
#88
2c3dbd0Thanks @glasser! - When passingparamsas an object, parameters withundefinedvalues are now skipped, like withJSON.stringify. So you can write:getUser(query: string | undefined) { return this.get('user', { params: { query } }); }
and if
queryis not provided, thequeryparameter will be left off of the URL instead of given the valueundefined.As part of this change, we've removed the ability to provide
paramsin formats other than this kind of object or as anURLSearchParamsobject. Previously, we allowed every form of input that could be passed tonew URLSearchParams(). If you were using one of the other forms (like a pre-serialized URL string or an array of two-element arrays), just pass it directly tonew URLSearchParams; note that the feature of strippingundefinedvalues will not occur in this case. For example, you can replacethis.get('user', { params: [['query', query]] })withthis.get('user', { params: new URLSearchParams([['query', query]]) }). (URLSearchParamsis available in Node as a global.) - 
#107
4b2a6f9Thanks @trevor-scheer! - RemovedidReceiveResponsehookThe naming of this hook is deceiving; if this hook is overridden it becomes
responsible for returning the parsed body and handling errors if they occur. It
was originally introduced in
apollographql/apollo-server#1324, where the author
implemented it due to lack of access to the complete response (headers) in the
fetch methods (get, post, ...). This approach isn't a type safe way to
accomplish this and places the burden of body parsing and error handling on the
user.Removing this hook is a prerequisite to a subsequent change that will introduce
the ability to fetch a complete response (headers included) aside from the
provided fetch methods which only return a body. This change will reinstate the
functionality that the author of this hook had originally intended in a more
direct manner. - 
#95
c59b82fThanks @glasser! - Simplify interpretation ofthis.baseURLso it works exactly like links in a web browser.If you set
this.baseURLto an URL with a non-empty path component, this may change the URL that your methods talk to. Specifically:- Paths passed to methods such as 
this.get('/foo')now replace the entire URL path fromthis.baseURL. If you did not intend this, writethis.get('foo')instead. - If 
this.baseURLhas a non-empty path and does not end in a trailing slash, paths such asthis.get('foo')will replace the last component of the URL path instead of adding a new component. If you did not intend this, add a trailing slash tothis.baseURL. 
If you preferred the v4 semantics and do not want to make the changes described above, you can restore v4 semantics by overriding
resolveURLin your subclass with the following code from v4:override resolveURL(path: string): ValueOrPromise<URL> { if (path.startsWith('/')) { path = path.slice(1); } const baseURL = this.baseURL; if (baseURL) { const normalizedBaseURL = baseURL.endsWith('/') ? baseURL : baseURL.concat('/'); return new URL(path, normalizedBaseURL); } else { return new URL(path); } }
As part of this change, it is now possible to specify URLs whose first path segment contains a colon, such as
this.get('/foo:bar'). - Paths passed to methods such as 
 - 
#121
32f8f04Thanks @glasser! - We now write to the shared HTTP-header-sensitive cache in the background rather than before the fetch resolves. By default, errors talking to the cache are logged withconsole.log; overridecatchCacheWritePromiseErrorsto customize. If you callfetch(), the result object has ahttpCache.cacheWritePromisefield that you canawaitif you want to know when the cache write ends. 
Minor Changes
- [#117](https://gith...
 
v4.3.2
Patch Changes
- #57 
946d79eThanks @trevor-scheer! - Fix build process (again), ensure built directory exists before publish 
v4.3.1
Patch Changes
- #54 
aa0fa97Thanks @trevor-scheer! - Fix installation into non-TS repositories 
v4.3.0
Minor Changes
- #13 
adb7e81Thanks @trevor-scheer! - Official Apollo Server v4.0.0 support