summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhil Hughes <me@iamphill.com>2019-04-25 08:15:41 +0000
committerPhil Hughes <me@iamphill.com>2019-04-25 08:15:41 +0000
commit97678c09fd919b3fb2240dbe4d2a063a54780e55 (patch)
treea642d31110ca801aeb333bc7f25fe526928b2da5
parentd026deb219b454179c4bb348e48fe6426a418e2e (diff)
parent8e808bc221f1a7050629346df3748a6c608ff497 (diff)
downloadgitlab-ce-97678c09fd919b3fb2240dbe4d2a063a54780e55.tar.gz
Merge branch 'kp-add-base-url-support-graphql' into 'master'
Add support for baseUrl in ApolloClient instance within GraphQL helper See merge request gitlab-org/gitlab-ce!27657
-rw-r--r--app/assets/javascripts/lib/graphql.js14
1 files changed, 11 insertions, 3 deletions
diff --git a/app/assets/javascripts/lib/graphql.js b/app/assets/javascripts/lib/graphql.js
index ae02559415c..498c2348ca2 100644
--- a/app/assets/javascripts/lib/graphql.js
+++ b/app/assets/javascripts/lib/graphql.js
@@ -3,10 +3,17 @@ import { InMemoryCache } from 'apollo-cache-inmemory';
import { createUploadLink } from 'apollo-upload-client';
import csrf from '~/lib/utils/csrf';
-export default (resolvers = {}) =>
- new ApolloClient({
+export default (resolvers = {}, baseUrl = '') => {
+ let uri = `${gon.relative_url_root}/api/graphql`;
+
+ if (baseUrl) {
+ // Prepend baseUrl and ensure that `///` are replaced with `/`
+ uri = `${baseUrl}${uri}`.replace(/\/{3,}/g, '/');
+ }
+
+ return new ApolloClient({
link: createUploadLink({
- uri: `${gon.relative_url_root}/api/graphql`,
+ uri,
headers: {
[csrf.headerKey]: csrf.token,
},
@@ -14,3 +21,4 @@ export default (resolvers = {}) =>
cache: new InMemoryCache(),
resolvers,
});
+};