Commit d27596b2 authored by Kushal Pandya's avatar Kushal Pandya

Merge branch...

Merge branch '198624-disable-apollo-cache-on-the-cases-where-apollo-client-is-used-within-vuex' into 'master'

Disable Apollo cache if Apollo Client is used within Vuex

Closes #198624

See merge request gitlab-org/gitlab!23768
parents 4d7872ef 43326f78
...@@ -5,6 +5,14 @@ import { ApolloLink } from 'apollo-link'; ...@@ -5,6 +5,14 @@ import { ApolloLink } from 'apollo-link';
import { BatchHttpLink } from 'apollo-link-batch-http'; import { BatchHttpLink } from 'apollo-link-batch-http';
import csrf from '~/lib/utils/csrf'; import csrf from '~/lib/utils/csrf';
export const fetchPolicies = {
CACHE_FIRST: 'cache-first',
CACHE_AND_NETWORK: 'cache-and-network',
NETWORK_ONLY: 'network-only',
NO_CACHE: 'no-cache',
CACHE_ONLY: 'cache-only',
};
export default (resolvers = {}, config = {}) => { export default (resolvers = {}, config = {}) => {
let uri = `${gon.relative_url_root}/api/graphql`; let uri = `${gon.relative_url_root}/api/graphql`;
...@@ -32,5 +40,10 @@ export default (resolvers = {}, config = {}) => { ...@@ -32,5 +40,10 @@ export default (resolvers = {}, config = {}) => {
}), }),
resolvers, resolvers,
assumeImmutableResults: config.assumeImmutableResults, assumeImmutableResults: config.assumeImmutableResults,
defaultOptions: {
query: {
fetchPolicy: config.fetchPolicy || fetchPolicies.CACHE_FIRST,
},
},
}); });
}; };
import { omit } from 'lodash'; import { omit } from 'lodash';
import createGqClient from '~/lib/graphql'; import createGqClient, { fetchPolicies } from '~/lib/graphql';
import { getIdFromGraphQLId } from '~/graphql_shared/utils'; import { getIdFromGraphQLId } from '~/graphql_shared/utils';
export const gqClient = createGqClient(); export const gqClient = createGqClient(
{},
{
fetchPolicy: fetchPolicies.NO_CACHE,
},
);
export const uniqMetricsId = metric => `${metric.metric_id}_${metric.id}`; export const uniqMetricsId = metric => `${metric.metric_id}_${metric.id}`;
......
...@@ -3,6 +3,7 @@ import { ApolloMutation } from 'vue-apollo'; ...@@ -3,6 +3,7 @@ import { ApolloMutation } from 'vue-apollo';
import Mousetrap from 'mousetrap'; import Mousetrap from 'mousetrap';
import { GlLoadingIcon, GlAlert } from '@gitlab/ui'; import { GlLoadingIcon, GlAlert } from '@gitlab/ui';
import createFlash from '~/flash'; import createFlash from '~/flash';
import { fetchPolicies } from '~/lib/graphql';
import allVersionsMixin from '../../mixins/all_versions'; import allVersionsMixin from '../../mixins/all_versions';
import Toolbar from '../../components/toolbar/index.vue'; import Toolbar from '../../components/toolbar/index.vue';
import DesignDiscussion from '../../components/design_notes/design_discussion.vue'; import DesignDiscussion from '../../components/design_notes/design_discussion.vue';
...@@ -70,7 +71,7 @@ export default { ...@@ -70,7 +71,7 @@ export default {
}, },
design: { design: {
query: getDesignQuery, query: getDesignQuery,
fetchPolicy: 'network-only', fetchPolicy: fetchPolicies.NETWORK_ONLY,
variables() { variables() {
return this.designVariables; return this.designVariables;
}, },
...@@ -215,7 +216,7 @@ export default { ...@@ -215,7 +216,7 @@ export default {
@done="$router.push({ name: $options.DESIGNS_ROUTE_NAME })" @done="$router.push({ name: $options.DESIGNS_ROUTE_NAME })"
@error="onDesignDeleteError" @error="onDesignDeleteError"
> >
<template v-slot="{ mutate, loading, error }"> <template v-slot="{ mutate, loading }">
<toolbar <toolbar
:id="id" :id="id"
:is-deleting="loading" :is-deleting="loading"
......
...@@ -3,13 +3,18 @@ import Cookies from 'js-cookie'; ...@@ -3,13 +3,18 @@ import Cookies from 'js-cookie';
import { __, s__, sprintf } from '~/locale'; import { __, s__, sprintf } from '~/locale';
import createGqClient from '~/lib/graphql'; import createGqClient, { fetchPolicies } from '~/lib/graphql';
import { parseBoolean } from '~/lib/utils/common_utils'; import { parseBoolean } from '~/lib/utils/common_utils';
import { dateInWords, parsePikadayDate } from '~/lib/utils/datetime_utility'; import { dateInWords, parsePikadayDate } from '~/lib/utils/datetime_utility';
import { dateTypes } from '../constants'; import { dateTypes } from '../constants';
const gqClient = createGqClient(); const gqClient = createGqClient(
{},
{
fetchPolicy: fetchPolicies.NO_CACHE,
},
);
const triggerDocumentEvent = (eventName, eventParam) => { const triggerDocumentEvent = (eventName, eventParam) => {
$(document).trigger(eventName, eventParam); $(document).trigger(eventName, eventParam);
......
...@@ -75,10 +75,7 @@ export const receiveItemsFailure = ({ commit }, data) => { ...@@ -75,10 +75,7 @@ export const receiveItemsFailure = ({ commit }, data) => {
flash(s__('Epics|Something went wrong while fetching child epics.')); flash(s__('Epics|Something went wrong while fetching child epics.'));
commit(types.RECEIVE_ITEMS_FAILURE, data); commit(types.RECEIVE_ITEMS_FAILURE, data);
}; };
export const fetchItems = ( export const fetchItems = ({ dispatch }, { parentItem, isSubItem = false }) => {
{ dispatch },
{ parentItem, isSubItem = false, fetchPolicy = 'cache-first' },
) => {
const { iid, fullPath } = parentItem; const { iid, fullPath } = parentItem;
dispatch('requestItems', { dispatch('requestItems', {
...@@ -90,7 +87,6 @@ export const fetchItems = ( ...@@ -90,7 +87,6 @@ export const fetchItems = (
.query({ .query({
query: epicChildren, query: epicChildren,
variables: { iid, fullPath }, variables: { iid, fullPath },
fetchPolicy,
}) })
.then(({ data }) => { .then(({ data }) => {
const children = processQueryResponse(data.group); const children = processQueryResponse(data.group);
...@@ -458,7 +454,6 @@ export const createNewIssue = ({ state, dispatch }, { issuesEndpoint, title }) = ...@@ -458,7 +454,6 @@ export const createNewIssue = ({ state, dispatch }, { issuesEndpoint, title }) =
.then(() => .then(() =>
dispatch('fetchItems', { dispatch('fetchItems', {
parentItem, parentItem,
fetchPolicy: 'network-only',
}), }),
) )
.catch(e => { .catch(e => {
......
import { PathIdSeparator } from 'ee/related_issues/constants'; import { PathIdSeparator } from 'ee/related_issues/constants';
import createGqClient from '~/lib/graphql'; import createGqClient, { fetchPolicies } from '~/lib/graphql';
import { ChildType } from '../constants'; import { ChildType } from '../constants';
export const gqClient = createGqClient(); export const gqClient = createGqClient(
{},
{
fetchPolicy: fetchPolicies.NO_CACHE,
},
);
/** /**
* Returns a numeric representation of item * Returns a numeric representation of item
......
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils'; import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
import { newDate, parsePikadayDate } from '~/lib/utils/datetime_utility'; import { newDate, parsePikadayDate } from '~/lib/utils/datetime_utility';
import createGqClient from '~/lib/graphql'; import createGqClient, { fetchPolicies } from '~/lib/graphql';
export const gqClient = createGqClient(); export const gqClient = createGqClient(
{},
{
fetchPolicy: fetchPolicies.NO_CACHE,
},
);
/** /**
* Updates provided `epic` object with necessary props * Updates provided `epic` object with necessary props
......
...@@ -9,8 +9,6 @@ import { ...@@ -9,8 +9,6 @@ import {
mockIssue1, mockIssue1,
} from '../../../javascripts/related_items_tree/mock_data'; } from '../../../javascripts/related_items_tree/mock_data';
jest.mock('~/lib/graphql', () => jest.fn());
describe('RelatedItemsTree', () => { describe('RelatedItemsTree', () => {
describe('epicUtils', () => { describe('epicUtils', () => {
describe('sortChildren', () => { describe('sortChildren', () => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment