2019-07-07 11:18:12 +05:30
|
|
|
import { ApolloClient } from 'apollo-client';
|
|
|
|
import { InMemoryCache } from 'apollo-cache-inmemory';
|
|
|
|
import { createUploadLink } from 'apollo-upload-client';
|
2019-02-15 15:39:39 +05:30
|
|
|
import csrf from '~/lib/utils/csrf';
|
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
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({
|
2019-07-07 11:18:12 +05:30
|
|
|
link: createUploadLink({
|
2019-07-31 22:56:46 +05:30
|
|
|
uri,
|
2019-07-07 11:18:12 +05:30
|
|
|
headers: {
|
|
|
|
[csrf.headerKey]: csrf.token,
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
cache: new InMemoryCache(),
|
|
|
|
resolvers,
|
|
|
|
});
|
2019-07-31 22:56:46 +05:30
|
|
|
};
|