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
This commit is contained in:
Phil Hughes 2019-04-25 08:15:41 +00:00
commit 97678c09fd
1 changed files with 11 additions and 3 deletions

View File

@ -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,
});
};