diff options
author | Phil Hughes <me@iamphill.com> | 2019-05-28 14:41:57 +0100 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2019-05-29 10:31:16 +0100 |
commit | 301a7d32b40128d388aa42b487de367c1cdbc1cd (patch) | |
tree | e5bdafc36c7a6a0204272d05615d04a9f31ae3b7 /app | |
parent | 4a9387242dbbfee9e9ddc7b46eb69ad6a2f4ba2c (diff) | |
download | gitlab-ce-301a7d32b40128d388aa42b487de367c1cdbc1cd.tar.gz |
Enable GraphQL batch requests
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/javascripts/lib/graphql.js | 20 | ||||
-rw-r--r-- | app/controllers/graphql_controller.rb | 3 |
2 files changed, 16 insertions, 7 deletions
diff --git a/app/assets/javascripts/lib/graphql.js b/app/assets/javascripts/lib/graphql.js index 47e91dedd5a..5857f9e22ae 100644 --- a/app/assets/javascripts/lib/graphql.js +++ b/app/assets/javascripts/lib/graphql.js @@ -1,6 +1,8 @@ import { ApolloClient } from 'apollo-client'; import { InMemoryCache } from 'apollo-cache-inmemory'; import { createUploadLink } from 'apollo-upload-client'; +import { ApolloLink } from 'apollo-link'; +import { BatchHttpLink } from 'apollo-link-batch-http'; import csrf from '~/lib/utils/csrf'; export default (resolvers = {}, config = {}) => { @@ -11,13 +13,19 @@ export default (resolvers = {}, config = {}) => { uri = `${config.baseUrl}${uri}`.replace(/\/{3,}/g, '/'); } + const httpOptions = { + uri, + headers: { + [csrf.headerKey]: csrf.token, + }, + }; + return new ApolloClient({ - link: createUploadLink({ - uri, - headers: { - [csrf.headerKey]: csrf.token, - }, - }), + link: ApolloLink.split( + operation => operation.getContext().hasUpload, + createUploadLink(httpOptions), + new BatchHttpLink(httpOptions), + ), cache: new InMemoryCache(config.cacheConfig), resolvers, }); diff --git a/app/controllers/graphql_controller.rb b/app/controllers/graphql_controller.rb index e8f38899647..1ce0afac83b 100644 --- a/app/controllers/graphql_controller.rb +++ b/app/controllers/graphql_controller.rb @@ -53,7 +53,8 @@ class GraphqlController < ApplicationController { query: single_query_info[:query], variables: build_variables(single_query_info[:variables]), - operation_name: single_query_info[:operationName] + operation_name: single_query_info[:operationName], + context: context } end end |