Commit f6ce5527 authored by Frédéric Caplette's avatar Frédéric Caplette Committed by Natalia Tepluhina

Replace writeQuery calls in pipeline_editor app with client mutations

parent 033444cf
...@@ -11,7 +11,6 @@ import commitCIFile from '../../graphql/mutations/commit_ci_file.mutation.graphq ...@@ -11,7 +11,6 @@ import commitCIFile from '../../graphql/mutations/commit_ci_file.mutation.graphq
import updateCurrentBranchMutation from '../../graphql/mutations/update_current_branch.mutation.graphql'; import updateCurrentBranchMutation from '../../graphql/mutations/update_current_branch.mutation.graphql';
import updateLastCommitBranchMutation from '../../graphql/mutations/update_last_commit_branch.mutation.graphql'; import updateLastCommitBranchMutation from '../../graphql/mutations/update_last_commit_branch.mutation.graphql';
import getCurrentBranch from '../../graphql/queries/client/current_branch.graphql'; import getCurrentBranch from '../../graphql/queries/client/current_branch.graphql';
import getIsNewCiConfigFile from '../../graphql/queries/client/is_new_ci_config_file.graphql';
import getPipelineEtag from '../../graphql/queries/client/pipeline_etag.graphql'; import getPipelineEtag from '../../graphql/queries/client/pipeline_etag.graphql';
import CommitForm from './commit_form.vue'; import CommitForm from './commit_form.vue';
...@@ -41,18 +40,19 @@ export default { ...@@ -41,18 +40,19 @@ export default {
required: false, required: false,
default: '', default: '',
}, },
isNewCiConfigFile: {
type: Boolean,
required: false,
default: false,
},
}, },
data() { data() {
return { return {
commit: {}, commit: {},
isNewCiConfigFile: false,
isSaving: false, isSaving: false,
}; };
}, },
apollo: { apollo: {
isNewCiConfigFile: {
query: getIsNewCiConfigFile,
},
currentBranch: { currentBranch: {
query: getCurrentBranch, query: getCurrentBranch,
}, },
......
mutation updateAppStatus($appStatus: String) {
updateAppStatus(appStatus: $appStatus) @client
}
import produce from 'immer';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import getAppStatus from './queries/client/app_status.graphql';
import getCurrentBranchQuery from './queries/client/current_branch.graphql'; import getCurrentBranchQuery from './queries/client/current_branch.graphql';
import getLastCommitBranchQuery from './queries/client/last_commit_branch.query.graphql'; import getLastCommitBranchQuery from './queries/client/last_commit_branch.query.graphql';
...@@ -31,20 +31,22 @@ export const resolvers = { ...@@ -31,20 +31,22 @@ export const resolvers = {
__typename: 'CiLintContent', __typename: 'CiLintContent',
})); }));
}, },
updateAppStatus: (_, { appStatus }, { cache }) => {
cache.writeQuery({
query: getAppStatus,
data: { appStatus },
});
},
updateCurrentBranch: (_, { currentBranch }, { cache }) => { updateCurrentBranch: (_, { currentBranch }, { cache }) => {
cache.writeQuery({ cache.writeQuery({
query: getCurrentBranchQuery, query: getCurrentBranchQuery,
data: produce(cache.readQuery({ query: getCurrentBranchQuery }), (draftData) => { data: { currentBranch },
draftData.currentBranch = currentBranch;
}),
}); });
}, },
updateLastCommitBranch: (_, { lastCommitBranch }, { cache }) => { updateLastCommitBranch: (_, { lastCommitBranch }, { cache }) => {
cache.writeQuery({ cache.writeQuery({
query: getLastCommitBranchQuery, query: getLastCommitBranchQuery,
data: produce(cache.readQuery({ query: getLastCommitBranchQuery }), (draftData) => { data: { lastCommitBranch },
draftData.lastCommitBranch = lastCommitBranch;
}),
}); });
}, },
}, },
......
...@@ -3,8 +3,10 @@ import Vue from 'vue'; ...@@ -3,8 +3,10 @@ import Vue from 'vue';
import VueApollo from 'vue-apollo'; import VueApollo from 'vue-apollo';
import createDefaultClient from '~/lib/graphql'; import createDefaultClient from '~/lib/graphql';
import { resetServiceWorkersPublicPath } from '../lib/utils/webpack'; import { resetServiceWorkersPublicPath } from '../lib/utils/webpack';
import { EDITOR_APP_STATUS_LOADING } from './constants';
import { CODE_SNIPPET_SOURCE_SETTINGS } from './components/code_snippet_alert/constants'; import { CODE_SNIPPET_SOURCE_SETTINGS } from './components/code_snippet_alert/constants';
import getCurrentBranch from './graphql/queries/client/current_branch.graphql'; import getCurrentBranch from './graphql/queries/client/current_branch.graphql';
import getAppStatus from './graphql/queries/client/app_status.graphql';
import getLastCommitBranchQuery from './graphql/queries/client/last_commit_branch.query.graphql'; import getLastCommitBranchQuery from './graphql/queries/client/last_commit_branch.query.graphql';
import getPipelineEtag from './graphql/queries/client/pipeline_etag.graphql'; import getPipelineEtag from './graphql/queries/client/pipeline_etag.graphql';
import { resolvers } from './graphql/resolvers'; import { resolvers } from './graphql/resolvers';
...@@ -64,6 +66,13 @@ export const initPipelineEditor = (selector = '#js-pipeline-editor') => { ...@@ -64,6 +66,13 @@ export const initPipelineEditor = (selector = '#js-pipeline-editor') => {
}); });
const { cache } = apolloProvider.clients.defaultClient; const { cache } = apolloProvider.clients.defaultClient;
cache.writeQuery({
query: getAppStatus,
data: {
appStatus: EDITOR_APP_STATUS_LOADING,
},
});
cache.writeQuery({ cache.writeQuery({
query: getCurrentBranch, query: getCurrentBranch,
data: { data: {
......
...@@ -17,11 +17,11 @@ import { ...@@ -17,11 +17,11 @@ import {
LOAD_FAILURE_UNKNOWN, LOAD_FAILURE_UNKNOWN,
STARTER_TEMPLATE_NAME, STARTER_TEMPLATE_NAME,
} from './constants'; } from './constants';
import updateAppStatus from './graphql/mutations/update_app_status.mutation.graphql';
import getBlobContent from './graphql/queries/blob_content.graphql'; import getBlobContent from './graphql/queries/blob_content.graphql';
import getCiConfigData from './graphql/queries/ci_config.graphql'; import getCiConfigData from './graphql/queries/ci_config.graphql';
import getAppStatus from './graphql/queries/client/app_status.graphql'; import getAppStatus from './graphql/queries/client/app_status.graphql';
import getCurrentBranch from './graphql/queries/client/current_branch.graphql'; import getCurrentBranch from './graphql/queries/client/current_branch.graphql';
import getIsNewCiConfigFile from './graphql/queries/client/is_new_ci_config_file.graphql';
import getTemplate from './graphql/queries/get_starter_template.query.graphql'; import getTemplate from './graphql/queries/get_starter_template.query.graphql';
import getLatestCommitShaQuery from './graphql/queries/latest_commit_sha.query.graphql'; import getLatestCommitShaQuery from './graphql/queries/latest_commit_sha.query.graphql';
import PipelineEditorHome from './pipeline_editor_home.vue'; import PipelineEditorHome from './pipeline_editor_home.vue';
...@@ -44,20 +44,20 @@ export default { ...@@ -44,20 +44,20 @@ export default {
}, },
data() { data() {
return { return {
starterTemplateName: STARTER_TEMPLATE_NAME,
ciConfigData: {}, ciConfigData: {},
currentCiFileContent: '',
failureType: null, failureType: null,
failureReasons: [], failureReasons: [],
initialCiFileContent: '', initialCiFileContent: '',
isFetchingCommitSha: false, isFetchingCommitSha: false,
isNewCiConfigFile: false, isNewCiConfigFile: false,
lastCommittedContent: '', lastCommittedContent: '',
currentCiFileContent: '', showFailure: false,
successType: null,
showStartScreen: false, showStartScreen: false,
showSuccess: false, showSuccess: false,
showFailure: false,
starterTemplate: '', starterTemplate: '',
starterTemplateName: STARTER_TEMPLATE_NAME,
successType: null,
}; };
}, },
...@@ -179,9 +179,6 @@ export default { ...@@ -179,9 +179,6 @@ export default {
currentBranch: { currentBranch: {
query: getCurrentBranch, query: getCurrentBranch,
}, },
isNewCiConfigFile: {
query: getIsNewCiConfigFile,
},
starterTemplate: { starterTemplate: {
query: getTemplate, query: getTemplate,
variables() { variables() {
...@@ -261,12 +258,10 @@ export default { ...@@ -261,12 +258,10 @@ export default {
this.currentCiFileContent = this.lastCommittedContent; this.currentCiFileContent = this.lastCommittedContent;
}, },
setAppStatus(appStatus) { setAppStatus(appStatus) {
this.$apollo.getClient().writeQuery({ query: getAppStatus, data: { appStatus } }); this.$apollo.mutate({ mutation: updateAppStatus, variables: { appStatus } });
}, },
setNewEmptyCiConfigFile() { setNewEmptyCiConfigFile() {
this.$apollo this.isNewCiConfigFile = true;
.getClient()
.writeQuery({ query: getIsNewCiConfigFile, data: { isNewCiConfigFile: true } });
this.showStartScreen = false; this.showStartScreen = false;
}, },
showErrorAlert({ type, reasons = [] }) { showErrorAlert({ type, reasons = [] }) {
...@@ -283,9 +278,7 @@ export default { ...@@ -283,9 +278,7 @@ export default {
this.reportSuccess(type); this.reportSuccess(type);
if (this.isNewCiConfigFile) { if (this.isNewCiConfigFile) {
this.$apollo this.isNewCiConfigFile = false;
.getClient()
.writeQuery({ query: getIsNewCiConfigFile, data: { isNewCiConfigFile: false } });
} }
// Keep track of the latest committed content to know // Keep track of the latest committed content to know
......
...@@ -125,6 +125,7 @@ export default { ...@@ -125,6 +125,7 @@ export default {
:ref="$options.commitSectionRef" :ref="$options.commitSectionRef"
:ci-file-content="ciFileContent" :ci-file-content="ciFileContent"
:commit-sha="commitSha" :commit-sha="commitSha"
:is-new-ci-config-file="isNewCiConfigFile"
v-on="$listeners" v-on="$listeners"
/> />
<pipeline-editor-drawer /> <pipeline-editor-drawer />
......
...@@ -52,6 +52,7 @@ describe('Pipeline Editor | Commit section', () => { ...@@ -52,6 +52,7 @@ describe('Pipeline Editor | Commit section', () => {
const defaultProps = { const defaultProps = {
ciFileContent: mockCiYml, ciFileContent: mockCiYml,
commitSha: mockCommitSha, commitSha: mockCommitSha,
isNewCiConfigFile: false,
}; };
const createComponent = ({ props = {}, options = {}, provide = {} } = {}) => { const createComponent = ({ props = {}, options = {}, provide = {} } = {}) => {
...@@ -72,7 +73,6 @@ describe('Pipeline Editor | Commit section', () => { ...@@ -72,7 +73,6 @@ describe('Pipeline Editor | Commit section', () => {
data() { data() {
return { return {
currentBranch: mockDefaultBranch, currentBranch: mockDefaultBranch,
isNewCiConfigFile: Boolean(options?.isNewCiConfigfile),
}; };
}, },
mocks: { mocks: {
...@@ -115,7 +115,7 @@ describe('Pipeline Editor | Commit section', () => { ...@@ -115,7 +115,7 @@ describe('Pipeline Editor | Commit section', () => {
describe('when the user commits a new file', () => { describe('when the user commits a new file', () => {
beforeEach(async () => { beforeEach(async () => {
createComponent({ options: { isNewCiConfigfile: true } }); createComponent({ props: { isNewCiConfigFile: true } });
await submitCommit(); await submitCommit();
}); });
......
...@@ -35,6 +35,17 @@ job_build: ...@@ -35,6 +35,17 @@ job_build:
- echo "build" - echo "build"
needs: ["job_test_2"] needs: ["job_test_2"]
`; `;
export const mockCiTemplateQueryResponse = {
data: {
project: {
ciTemplate: {
content: mockCiYml,
},
},
},
};
export const mockBlobContentQueryResponse = { export const mockBlobContentQueryResponse = {
data: { data: {
project: { repository: { blobs: { nodes: [{ rawBlob: mockCiYml }] } } }, project: { repository: { blobs: { nodes: [{ rawBlob: mockCiYml }] } } },
......
...@@ -11,17 +11,21 @@ import PipelineEditorMessages from '~/pipeline_editor/components/ui/pipeline_edi ...@@ -11,17 +11,21 @@ import PipelineEditorMessages from '~/pipeline_editor/components/ui/pipeline_edi
import { COMMIT_SUCCESS, COMMIT_FAILURE } from '~/pipeline_editor/constants'; import { COMMIT_SUCCESS, COMMIT_FAILURE } from '~/pipeline_editor/constants';
import getBlobContent from '~/pipeline_editor/graphql/queries/blob_content.graphql'; import getBlobContent from '~/pipeline_editor/graphql/queries/blob_content.graphql';
import getCiConfigData from '~/pipeline_editor/graphql/queries/ci_config.graphql'; import getCiConfigData from '~/pipeline_editor/graphql/queries/ci_config.graphql';
import getPipelineQuery from '~/pipeline_editor/graphql/queries/client/pipeline.graphql';
import getTemplate from '~/pipeline_editor/graphql/queries/get_starter_template.query.graphql'; import getTemplate from '~/pipeline_editor/graphql/queries/get_starter_template.query.graphql';
import getLatestCommitShaQuery from '~/pipeline_editor/graphql/queries/latest_commit_sha.query.graphql'; import getLatestCommitShaQuery from '~/pipeline_editor/graphql/queries/latest_commit_sha.query.graphql';
import getPipelineQuery from '~/pipeline_editor/graphql/queries/client/pipeline.graphql';
import PipelineEditorApp from '~/pipeline_editor/pipeline_editor_app.vue'; import PipelineEditorApp from '~/pipeline_editor/pipeline_editor_app.vue';
import PipelineEditorHome from '~/pipeline_editor/pipeline_editor_home.vue'; import PipelineEditorHome from '~/pipeline_editor/pipeline_editor_home.vue';
import { import {
mockCiConfigPath, mockCiConfigPath,
mockCiConfigQueryResponse, mockCiConfigQueryResponse,
mockBlobContentQueryResponse, mockBlobContentQueryResponse,
mockBlobContentQueryResponseNoCiFile, mockBlobContentQueryResponseNoCiFile,
mockCiYml, mockCiYml,
mockCiTemplateQueryResponse,
mockCommitSha, mockCommitSha,
mockCommitShaResults, mockCommitShaResults,
mockDefaultBranch, mockDefaultBranch,
...@@ -79,7 +83,7 @@ describe('Pipeline editor app component', () => { ...@@ -79,7 +83,7 @@ describe('Pipeline editor app component', () => {
}); });
}; };
const createComponentWithApollo = async ({ props = {}, provide = {}, stubs = {} } = {}) => { const createComponentWithApollo = async ({ provide = {}, stubs = {} } = {}) => {
const handlers = [ const handlers = [
[getBlobContent, mockBlobContentData], [getBlobContent, mockBlobContentData],
[getCiConfigData, mockCiConfigData], [getCiConfigData, mockCiConfigData],
...@@ -87,7 +91,6 @@ describe('Pipeline editor app component', () => { ...@@ -87,7 +91,6 @@ describe('Pipeline editor app component', () => {
[getLatestCommitShaQuery, mockLatestCommitShaQuery], [getLatestCommitShaQuery, mockLatestCommitShaQuery],
[getPipelineQuery, mockPipelineQuery], [getPipelineQuery, mockPipelineQuery],
]; ];
mockApollo = createMockApollo(handlers); mockApollo = createMockApollo(handlers);
const options = { const options = {
...@@ -95,13 +98,15 @@ describe('Pipeline editor app component', () => { ...@@ -95,13 +98,15 @@ describe('Pipeline editor app component', () => {
data() { data() {
return { return {
currentBranch: mockDefaultBranch, currentBranch: mockDefaultBranch,
lastCommitBranch: '',
appStatus: '',
}; };
}, },
mocks: {}, mocks: {},
apolloProvider: mockApollo, apolloProvider: mockApollo,
}; };
createComponent({ props, provide, stubs, options }); createComponent({ provide, stubs, options });
return waitForPromises(); return waitForPromises();
}; };
...@@ -199,7 +204,7 @@ describe('Pipeline editor app component', () => { ...@@ -199,7 +204,7 @@ describe('Pipeline editor app component', () => {
it('shows a unkown error message', async () => { it('shows a unkown error message', async () => {
const loadUnknownFailureText = 'The CI configuration was not loaded, please try again.'; const loadUnknownFailureText = 'The CI configuration was not loaded, please try again.';
mockBlobContentData.mockRejectedValueOnce(new Error('My error!')); mockBlobContentData.mockRejectedValueOnce();
await createComponentWithApollo({ await createComponentWithApollo({
stubs: { stubs: {
PipelineEditorMessages, PipelineEditorMessages,
...@@ -344,6 +349,8 @@ describe('Pipeline editor app component', () => { ...@@ -344,6 +349,8 @@ describe('Pipeline editor app component', () => {
describe('when refetching content', () => { describe('when refetching content', () => {
beforeEach(() => { beforeEach(() => {
mockBlobContentData.mockResolvedValue(mockBlobContentQueryResponse);
mockCiConfigData.mockResolvedValue(mockCiConfigQueryResponse);
mockLatestCommitShaQuery.mockResolvedValue(mockCommitShaResults); mockLatestCommitShaQuery.mockResolvedValue(mockCommitShaResults);
}); });
...@@ -379,7 +386,10 @@ describe('Pipeline editor app component', () => { ...@@ -379,7 +386,10 @@ describe('Pipeline editor app component', () => {
const originalLocation = window.location.href; const originalLocation = window.location.href;
beforeEach(() => { beforeEach(() => {
mockBlobContentData.mockResolvedValue(mockBlobContentQueryResponse);
mockCiConfigData.mockResolvedValue(mockCiConfigQueryResponse);
mockLatestCommitShaQuery.mockResolvedValue(mockCommitShaResults); mockLatestCommitShaQuery.mockResolvedValue(mockCommitShaResults);
mockGetTemplate.mockResolvedValue(mockCiTemplateQueryResponse);
setWindowLocation('?template=Android'); setWindowLocation('?template=Android');
}); });
......
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