From 26977b5175237cfbe8f7375d2734f0efb512a6e6 Mon Sep 17 00:00:00 2001 From: glo11372 Date: Wed, 28 Feb 2024 11:56:19 +0530 Subject: [PATCH 1/3] PWA-3154:GraphQL cacheable requests always have Authorization Bearer header --- packages/peregrine/lib/Apollo/links/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/peregrine/lib/Apollo/links/index.js b/packages/peregrine/lib/Apollo/links/index.js index 1a6bf48b1e..acf4498d8b 100644 --- a/packages/peregrine/lib/Apollo/links/index.js +++ b/packages/peregrine/lib/Apollo/links/index.js @@ -54,7 +54,7 @@ const getLinks = apiBase => { const links = new Map() .set('MUTATION_QUEUE', mutationQueueLink) .set('RETRY', retryLink) - .set('AUTH', authLink) + // .set('AUTH', authLink) .set('GQL_CACHE', gqlCacheLink) .set('STORE', storeLink) .set('ERROR', errorLink) From 34b2d4403400aac14e905d78a86375c14fbd4b2d Mon Sep 17 00:00:00 2001 From: glo11372 Date: Wed, 28 Feb 2024 12:34:53 +0530 Subject: [PATCH 2/3] pwa-3154: GraphQL cacheable requests always have Authorization Bearer header for testing only --- .../peregrine/lib/Apollo/links/__tests__/index.spec.js | 8 ++++---- packages/peregrine/lib/Apollo/links/authLink.js | 8 ++++---- packages/peregrine/lib/Apollo/links/index.js | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/peregrine/lib/Apollo/links/__tests__/index.spec.js b/packages/peregrine/lib/Apollo/links/__tests__/index.spec.js index 7185d08491..a538dfd4e0 100644 --- a/packages/peregrine/lib/Apollo/links/__tests__/index.spec.js +++ b/packages/peregrine/lib/Apollo/links/__tests__/index.spec.js @@ -7,10 +7,10 @@ jest.mock('@apollo/client', () => ({ __esModule: true, createHttpLink: jest.fn(() => 'http') })); -jest.mock('@magento/peregrine/lib/Apollo/links/authLink', () => ({ - __esModule: true, - default: jest.fn(() => 'auth') -})); +// jest.mock('@magento/peregrine/lib/Apollo/links/authLink', () => ({ +// __esModule: true, +// default: jest.fn(() => 'auth') +// })); jest.mock('@magento/peregrine/lib/Apollo/links/errorLink', () => ({ __esModule: true, default: jest.fn(() => 'error') diff --git a/packages/peregrine/lib/Apollo/links/authLink.js b/packages/peregrine/lib/Apollo/links/authLink.js index bb6be29d93..9247a9a45c 100644 --- a/packages/peregrine/lib/Apollo/links/authLink.js +++ b/packages/peregrine/lib/Apollo/links/authLink.js @@ -1,18 +1,18 @@ import { setContext } from '@apollo/client/link/context'; -import { BrowserPersistence } from '@magento/peregrine/lib/util'; +// import { BrowserPersistence } from '@magento/peregrine/lib/util'; -const storage = new BrowserPersistence(); +// const storage = new BrowserPersistence(); export default function createAuthLink() { return setContext((_, { headers }) => { // get the authentication token from local storage if it exists. - const token = storage.getItem('signin_token'); + // const token = storage.getItem('signin_token'); // return the headers to the context so httpLink can read them return { headers: { ...headers, - authorization: token ? `Bearer ${token}` : '' + // authorization: token ? `Bearer ${token}` : '' } }; }); diff --git a/packages/peregrine/lib/Apollo/links/index.js b/packages/peregrine/lib/Apollo/links/index.js index acf4498d8b..1a6bf48b1e 100644 --- a/packages/peregrine/lib/Apollo/links/index.js +++ b/packages/peregrine/lib/Apollo/links/index.js @@ -54,7 +54,7 @@ const getLinks = apiBase => { const links = new Map() .set('MUTATION_QUEUE', mutationQueueLink) .set('RETRY', retryLink) - // .set('AUTH', authLink) + .set('AUTH', authLink) .set('GQL_CACHE', gqlCacheLink) .set('STORE', storeLink) .set('ERROR', errorLink) From 02ae675a7068b3cc02d22531d46c0bba02b46e6f Mon Sep 17 00:00:00 2001 From: glo11372 Date: Thu, 29 Feb 2024 13:56:39 +0530 Subject: [PATCH 3/3] pwa-3154: GraphQL cacheable requests always have Authorization Bearer header run all test --- .../Apollo/links/__tests__/__snapshots__/index.spec.js.snap | 1 - packages/peregrine/lib/Apollo/links/authLink.js | 2 +- packages/peregrine/lib/Apollo/links/index.js | 6 +++--- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/peregrine/lib/Apollo/links/__tests__/__snapshots__/index.spec.js.snap b/packages/peregrine/lib/Apollo/links/__tests__/__snapshots__/index.spec.js.snap index 1b3428cfe5..e9eb130057 100644 --- a/packages/peregrine/lib/Apollo/links/__tests__/__snapshots__/index.spec.js.snap +++ b/packages/peregrine/lib/Apollo/links/__tests__/__snapshots__/index.spec.js.snap @@ -4,7 +4,6 @@ exports[`returns a map with expected keys and values 1`] = ` Map { "MUTATION_QUEUE" => "mutationQueue", "RETRY" => "retry", - "AUTH" => "auth", "GQL_CACHE" => "gqlCache", "STORE" => "store", "ERROR" => "error", diff --git a/packages/peregrine/lib/Apollo/links/authLink.js b/packages/peregrine/lib/Apollo/links/authLink.js index 9247a9a45c..c5efd6eaf6 100644 --- a/packages/peregrine/lib/Apollo/links/authLink.js +++ b/packages/peregrine/lib/Apollo/links/authLink.js @@ -11,7 +11,7 @@ export default function createAuthLink() { // return the headers to the context so httpLink can read them return { headers: { - ...headers, + ...headers // authorization: token ? `Bearer ${token}` : '' } }; diff --git a/packages/peregrine/lib/Apollo/links/index.js b/packages/peregrine/lib/Apollo/links/index.js index 1a6bf48b1e..5d867985c8 100644 --- a/packages/peregrine/lib/Apollo/links/index.js +++ b/packages/peregrine/lib/Apollo/links/index.js @@ -1,6 +1,6 @@ import { createHttpLink } from '@apollo/client'; -import createAuthLink from '@magento/peregrine/lib/Apollo/links/authLink'; +// import createAuthLink from '@magento/peregrine/lib/Apollo/links/authLink'; import createErrorLink from '@magento/peregrine/lib/Apollo/links/errorLink'; import createGqlCacheLink from '@magento/peregrine/lib/Apollo/links/gqlCacheLink'; import createMutationQueueLink from '@magento/peregrine/lib/Apollo/links/mutationQueueLink'; @@ -32,7 +32,7 @@ export const customFetchToShrinkQuery = (uri, options) => { }; const getLinks = apiBase => { - const authLink = createAuthLink(); + // const authLink = createAuthLink(); const storeLink = createStoreLink(); const errorLink = createErrorLink(); const retryLink = createRetryLink(); @@ -54,7 +54,7 @@ const getLinks = apiBase => { const links = new Map() .set('MUTATION_QUEUE', mutationQueueLink) .set('RETRY', retryLink) - .set('AUTH', authLink) + // .set('AUTH', authLink) .set('GQL_CACHE', gqlCacheLink) .set('STORE', storeLink) .set('ERROR', errorLink)