Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GraphQL cacheable requests always have "Authorization Bearer" header #4237

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions packages/peregrine/lib/Apollo/links/__tests__/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
10 changes: 5 additions & 5 deletions packages/peregrine/lib/Apollo/links/authLink.js
Original file line number Diff line number Diff line change
@@ -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}` : ''
...headers
// authorization: token ? `Bearer ${token}` : ''
}
};
});
Expand Down
6 changes: 3 additions & 3 deletions packages/peregrine/lib/Apollo/links/index.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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();
Expand All @@ -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)
Expand Down