summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorPhil Hughes <me@iamphill.com>2019-05-28 14:41:57 +0100
committerPhil Hughes <me@iamphill.com>2019-05-29 10:31:16 +0100
commit301a7d32b40128d388aa42b487de367c1cdbc1cd (patch)
treee5bdafc36c7a6a0204272d05615d04a9f31ae3b7 /app
parent4a9387242dbbfee9e9ddc7b46eb69ad6a2f4ba2c (diff)
downloadgitlab-ce-301a7d32b40128d388aa42b487de367c1cdbc1cd.tar.gz
Enable GraphQL batch requests
Diffstat (limited to 'app')
-rw-r--r--app/assets/javascripts/lib/graphql.js20
-rw-r--r--app/controllers/graphql_controller.rb3
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