diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-18 13:34:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-18 13:34:06 +0300 |
commit | 859a6fb938bb9ee2a317c46dfa4fcc1af49608f0 (patch) | |
tree | d7f2700abe6b4ffcb2dcfc80631b2d87d0609239 /app/assets/javascripts/lib/graphql.js | |
parent | 446d496a6d000c73a304be52587cd9bbc7493136 (diff) |
Add latest changes from gitlab-org/gitlab@13-9-stable-eev13.9.0-rc42
Diffstat (limited to 'app/assets/javascripts/lib/graphql.js')
-rw-r--r-- | app/assets/javascripts/lib/graphql.js | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/app/assets/javascripts/lib/graphql.js b/app/assets/javascripts/lib/graphql.js index 5c4bb5ea01f..bda5550a9f4 100644 --- a/app/assets/javascripts/lib/graphql.js +++ b/app/assets/javascripts/lib/graphql.js @@ -1,11 +1,11 @@ -import { ApolloClient } from 'apollo-client'; import { InMemoryCache } from 'apollo-cache-inmemory'; -import { createUploadLink } from 'apollo-upload-client'; +import { ApolloClient } from 'apollo-client'; import { ApolloLink } from 'apollo-link'; import { BatchHttpLink } from 'apollo-link-batch-http'; +import { createUploadLink } from 'apollo-upload-client'; +import { StartupJSLink } from '~/lib/utils/apollo_startup_js_link'; import csrf from '~/lib/utils/csrf'; import PerformanceBarService from '~/performance_bar/services/performance_bar_service'; -import { StartupJSLink } from '~/lib/utils/apollo_startup_js_link'; export const fetchPolicies = { CACHE_FIRST: 'cache-first', @@ -35,6 +35,16 @@ export default (resolvers = {}, config = {}) => { batchMax: config.batchMax || 10, }; + const requestCounterLink = new ApolloLink((operation, forward) => { + window.pendingApolloRequests = window.pendingApolloRequests || 0; + window.pendingApolloRequests += 1; + + return forward(operation).map((response) => { + window.pendingApolloRequests -= 1; + return response; + }); + }); + const uploadsLink = ApolloLink.split( (operation) => operation.getContext().hasUpload || operation.getContext().isSingleRequest, createUploadLink(httpOptions), @@ -63,7 +73,12 @@ export default (resolvers = {}, config = {}) => { return new ApolloClient({ typeDefs: config.typeDefs, - link: ApolloLink.from([performanceBarLink, new StartupJSLink(), uploadsLink]), + link: ApolloLink.from([ + requestCounterLink, + performanceBarLink, + new StartupJSLink(), + uploadsLink, + ]), cache: new InMemoryCache({ ...config.cacheConfig, freezeResults: config.assumeImmutableResults, |