From 7385725115169b0ad13dc7e1dab11c8c1a4c7aed Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Tue, 23 Nov 2021 14:42:39 -0500 Subject: [PATCH] Undo breaking change to `selectHttpOptionsBody` signature (#9103) --- CHANGELOG.md | 7 ++++ src/__tests__/__snapshots__/exports.ts.snap | 3 ++ src/link/batch-http/batchHttpLink.ts | 4 +-- .../__tests__/selectHttpOptionsAndBody.ts | 11 ++---- src/link/http/createHttpLink.ts | 4 +-- src/link/http/index.ts | 1 + src/link/http/selectHttpOptionsAndBody.ts | 35 +++++++++++-------- 7 files changed, 38 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cbc135bc2e6..82d62878f89 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## Apollo Client 3.5.5 (unreleased) + +### Bug Fixes + +- Remove `printer: Printer` positional parameter from publicly-exported `selectHttpOptionsAndBody` function, whose addition in [#8699](https://github.com/apollographql/apollo-client/pull/8699) was a breaking change (starting in Apollo Client 3.5.0) for direct consumers of `selectHttpOptionsAndBody`.
+ [@benjamn](https://github.com/benjamn) in [#9103](https://github.com/apollographql/apollo-client/pull/9103) + ## Apollo Client 3.5.4 (2021-11-19) ### Notices diff --git a/src/__tests__/__snapshots__/exports.ts.snap b/src/__tests__/__snapshots__/exports.ts.snap index fb143d0c192..07fa0772c9d 100644 --- a/src/__tests__/__snapshots__/exports.ts.snap +++ b/src/__tests__/__snapshots__/exports.ts.snap @@ -46,6 +46,7 @@ Array [ "resetCaches", "rewriteURIForGET", "selectHttpOptionsAndBody", + "selectHttpOptionsAndBodyInternal", "selectURI", "serializeFetchParameter", "setLogVerbosity", @@ -118,6 +119,7 @@ Array [ "resetCaches", "rewriteURIForGET", "selectHttpOptionsAndBody", + "selectHttpOptionsAndBodyInternal", "selectURI", "serializeFetchParameter", "setLogVerbosity", @@ -182,6 +184,7 @@ Array [ "parseAndCheckHttpResponse", "rewriteURIForGET", "selectHttpOptionsAndBody", + "selectHttpOptionsAndBodyInternal", "selectURI", "serializeFetchParameter", ] diff --git a/src/link/batch-http/batchHttpLink.ts b/src/link/batch-http/batchHttpLink.ts index af46d0f2002..1a78e3b1411 100644 --- a/src/link/batch-http/batchHttpLink.ts +++ b/src/link/batch-http/batchHttpLink.ts @@ -6,7 +6,7 @@ import { selectURI, parseAndCheckHttpResponse, checkFetcher, - selectHttpOptionsAndBody, + selectHttpOptionsAndBodyInternal, defaultPrinter, fallbackHttpConfig, HttpOptions, @@ -96,7 +96,7 @@ export class BatchHttpLink extends ApolloLink { //uses fallback, link, and then context to build options const optsAndBody = operations.map(operation => - selectHttpOptionsAndBody( + selectHttpOptionsAndBodyInternal( operation, print, fallbackHttpConfig, diff --git a/src/link/http/__tests__/selectHttpOptionsAndBody.ts b/src/link/http/__tests__/selectHttpOptionsAndBody.ts index 9948075dc47..715a25aa3aa 100644 --- a/src/link/http/__tests__/selectHttpOptionsAndBody.ts +++ b/src/link/http/__tests__/selectHttpOptionsAndBody.ts @@ -4,7 +4,7 @@ import { ASTNode, print, stripIgnoredCharacters } from 'graphql'; import { createOperation } from '../../utils/createOperation'; import { selectHttpOptionsAndBody, - defaultPrinter, + selectHttpOptionsAndBodyInternal, fallbackHttpConfig, } from '../selectHttpOptionsAndBody'; @@ -20,7 +20,6 @@ describe('selectHttpOptionsAndBody', () => { it('includeQuery allows the query to be ignored', () => { const { body } = selectHttpOptionsAndBody( createOperation({}, { query }), - defaultPrinter, { http: { includeQuery: false } }, ); expect(body).not.toHaveProperty('query'); @@ -30,7 +29,6 @@ describe('selectHttpOptionsAndBody', () => { const extensions = { yo: 'what up' }; const { body } = selectHttpOptionsAndBody( createOperation({}, { query, extensions }), - defaultPrinter, { http: { includeExtensions: true } }, ); expect(body).toHaveProperty('extensions'); @@ -50,7 +48,6 @@ describe('selectHttpOptionsAndBody', () => { const extensions = { yo: 'what up' }; const { options, body } = selectHttpOptionsAndBody( createOperation({}, { query, extensions }), - defaultPrinter, fallbackHttpConfig, ); @@ -81,7 +78,6 @@ describe('selectHttpOptionsAndBody', () => { const { options, body } = selectHttpOptionsAndBody( createOperation({}, { query, extensions }), - defaultPrinter, fallbackHttpConfig, config, ); @@ -107,7 +103,6 @@ describe('selectHttpOptionsAndBody', () => { const config = { headers }; const { options, body } = selectHttpOptionsAndBody( createOperation({}, { query }), - defaultPrinter, fallbackHttpConfig, config, ); @@ -122,18 +117,16 @@ describe('selectHttpOptionsAndBody', () => { }); it('applies custom printer function when provided', () => { - const customPrinter = (ast: ASTNode, originalPrint: typeof print) => { return stripIgnoredCharacters(originalPrint(ast)); }; - const { body } = selectHttpOptionsAndBody( + const { body } = selectHttpOptionsAndBodyInternal( createOperation({}, { query }), customPrinter, fallbackHttpConfig, ); expect(body.query).toBe('query SampleQuery{stub{id}}'); - }); }); diff --git a/src/link/http/createHttpLink.ts b/src/link/http/createHttpLink.ts index 0ba3dbd2c3d..84aab27d809 100644 --- a/src/link/http/createHttpLink.ts +++ b/src/link/http/createHttpLink.ts @@ -9,7 +9,7 @@ import { selectURI } from './selectURI'; import { parseAndCheckHttpResponse } from './parseAndCheckHttpResponse'; import { checkFetcher } from './checkFetcher'; import { - selectHttpOptionsAndBody, + selectHttpOptionsAndBodyInternal, defaultPrinter, fallbackHttpConfig, HttpOptions @@ -82,7 +82,7 @@ export const createHttpLink = (linkOptions: HttpOptions = {}) => { }; //uses fallback, link, and then context to build options - const { options, body } = selectHttpOptionsAndBody( + const { options, body } = selectHttpOptionsAndBodyInternal( operation, print, fallbackHttpConfig, diff --git a/src/link/http/index.ts b/src/link/http/index.ts index 66463608733..e0c9a5246c2 100644 --- a/src/link/http/index.ts +++ b/src/link/http/index.ts @@ -13,6 +13,7 @@ export { fallbackHttpConfig, defaultPrinter, selectHttpOptionsAndBody, + selectHttpOptionsAndBodyInternal, // needed by ../batch-http but not public UriFunction } from './selectHttpOptionsAndBody'; export { checkFetcher } from './checkFetcher'; diff --git a/src/link/http/selectHttpOptionsAndBody.ts b/src/link/http/selectHttpOptionsAndBody.ts index 45db5bae51f..02ef79dc78e 100644 --- a/src/link/http/selectHttpOptionsAndBody.ts +++ b/src/link/http/selectHttpOptionsAndBody.ts @@ -111,23 +111,27 @@ export const fallbackHttpConfig = { export const defaultPrinter: Printer = (ast, printer) => printer(ast); -export const selectHttpOptionsAndBody = ( +export function selectHttpOptionsAndBody( operation: Operation, - printer: Printer, fallbackConfig: HttpConfig, ...configs: Array -) => { - let options: HttpConfig & Record = { - ...fallbackConfig.options, - headers: fallbackConfig.headers, - credentials: fallbackConfig.credentials, - }; - let http: HttpQueryOptions = fallbackConfig.http || {}; +) { + configs.unshift(fallbackConfig); + return selectHttpOptionsAndBodyInternal( + operation, + defaultPrinter, + ...configs, + ); +} + +export function selectHttpOptionsAndBodyInternal( + operation: Operation, + printer: Printer, + ...configs: HttpConfig[] +) { + let options = {} as HttpConfig & Record; + let http = {} as HttpQueryOptions; - /* - * use the rest of the configs to populate the options - * configs later in the list will overwrite earlier fields - */ configs.forEach(config => { options = { ...options, @@ -137,7 +141,10 @@ export const selectHttpOptionsAndBody = ( ...headersToLowerCase(config.headers), }, }; - if (config.credentials) options.credentials = config.credentials; + + if (config.credentials) { + options.credentials = config.credentials; + } http = { ...http,