Commit 9fea0b50 authored by Marius Bobin's avatar Marius Bobin

Use GraphQL ETag caching on frontend

Use GraphQL ETag caching on frontend
parent 51f2e31f
...@@ -3,6 +3,7 @@ import { ApolloClient } from 'apollo-client'; ...@@ -3,6 +3,7 @@ import { ApolloClient } from 'apollo-client';
import { ApolloLink } from 'apollo-link'; import { ApolloLink } from 'apollo-link';
import { BatchHttpLink } from 'apollo-link-batch-http'; import { BatchHttpLink } from 'apollo-link-batch-http';
import { createUploadLink } from 'apollo-upload-client'; import { createUploadLink } from 'apollo-upload-client';
import { createHttpLink } from 'apollo-link-http';
import { StartupJSLink } from '~/lib/utils/apollo_startup_js_link'; import { StartupJSLink } from '~/lib/utils/apollo_startup_js_link';
import csrf from '~/lib/utils/csrf'; import csrf from '~/lib/utils/csrf';
import PerformanceBarService from '~/performance_bar/services/performance_bar_service'; import PerformanceBarService from '~/performance_bar/services/performance_bar_service';
...@@ -48,7 +49,7 @@ export default (resolvers = {}, config = {}) => { ...@@ -48,7 +49,7 @@ export default (resolvers = {}, config = {}) => {
const uploadsLink = ApolloLink.split( const uploadsLink = ApolloLink.split(
(operation) => operation.getContext().hasUpload || operation.getContext().isSingleRequest, (operation) => operation.getContext().hasUpload || operation.getContext().isSingleRequest,
createUploadLink(httpOptions), createUploadLink(httpOptions),
new BatchHttpLink(httpOptions), config.useGet ? createHttpLink(httpOptions) : new BatchHttpLink(httpOptions),
); );
const performanceBarLink = new ApolloLink((operation, forward) => { const performanceBarLink = new ApolloLink((operation, forward) => {
......
...@@ -38,6 +38,18 @@ export default { ...@@ -38,6 +38,18 @@ export default {
}, },
apollo: { apollo: {
pipeline: { pipeline: {
context() {
return {
fetchOptions: {
method: 'GET',
},
headers: {
'X-GITLAB-GRAPHQL-FEATURE-CORRELATION': 'verify/ci/pipeline-graph',
'X-GITLAB-GRAPHQL-RESOURCE-ETAG': `pipelines/id/${this.pipelineIid}`,
'X-REQUESTED_WITH': 'XMLHttpRequest',
},
}
},
query: getPipelineDetails, query: getPipelineDetails,
pollInterval: 10000, pollInterval: 10000,
variables() { variables() {
...@@ -49,7 +61,8 @@ export default { ...@@ -49,7 +61,8 @@ export default {
update(data) { update(data) {
return unwrapPipelineData(this.pipelineProjectPath, data); return unwrapPipelineData(this.pipelineProjectPath, data);
}, },
error() { error(err) {
console.log(err);
this.reportFailure(LOAD_FAILURE); this.reportFailure(LOAD_FAILURE);
}, },
}, },
......
...@@ -72,6 +72,15 @@ export default { ...@@ -72,6 +72,15 @@ export default {
this.$apollo.addSmartQuery('currentPipeline', { this.$apollo.addSmartQuery('currentPipeline', {
query: getPipelineDetails, query: getPipelineDetails,
pollInterval: 10000, pollInterval: 10000,
context: {
fetchOptions: {
method: 'GET',
},
headers: {
'X-GITLAB-GRAPHQL-FEATURE-CORRELATION': 'verify/ci/pipeline-graph',
'X-GITLAB-GRAPHQL-RESOURCE-ETAG': 'pipelines/id/123',
},
},
variables() { variables() {
return { return {
projectPath, projectPath,
......
...@@ -11,7 +11,7 @@ const apolloProvider = new VueApollo({ ...@@ -11,7 +11,7 @@ const apolloProvider = new VueApollo({
defaultClient: createDefaultClient( defaultClient: createDefaultClient(
{}, {},
{ {
batchMax: 2, useGet: true,
}, },
), ),
}); });
......
...@@ -1977,6 +1977,15 @@ apollo-link-http-common@^0.2.14, apollo-link-http-common@^0.2.16: ...@@ -1977,6 +1977,15 @@ apollo-link-http-common@^0.2.14, apollo-link-http-common@^0.2.16:
ts-invariant "^0.4.0" ts-invariant "^0.4.0"
tslib "^1.9.3" tslib "^1.9.3"
apollo-link-http@^1.5.17:
version "1.5.17"
resolved "https://registry.yarnpkg.com/apollo-link-http/-/apollo-link-http-1.5.17.tgz#499e9f1711bf694497f02c51af12d82de5d8d8ba"
integrity sha512-uWcqAotbwDEU/9+Dm9e1/clO7hTB2kQ/94JYcGouBVLjoKmTeJTUPQKcJGpPwUjZcSqgYicbFqQSoJIW0yrFvg==
dependencies:
apollo-link "^1.2.14"
apollo-link-http-common "^0.2.16"
tslib "^1.9.3"
apollo-link@^1.0.0, apollo-link@^1.2.12, apollo-link@^1.2.14: apollo-link@^1.0.0, apollo-link@^1.2.12, apollo-link@^1.2.14:
version "1.2.14" version "1.2.14"
resolved "https://registry.yarnpkg.com/apollo-link/-/apollo-link-1.2.14.tgz#3feda4b47f9ebba7f4160bef8b977ba725b684d9" resolved "https://registry.yarnpkg.com/apollo-link/-/apollo-link-1.2.14.tgz#3feda4b47f9ebba7f4160bef8b977ba725b684d9"
......
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