Commit 190173fb authored by Natalia Tepluhina's avatar Natalia Tepluhina

Merge branch '216186-setup-apollo-client' into 'master'

Set up graphql in Static Site Editor

See merge request gitlab-org/gitlab!30881
parents 342a19bf da48e80e
......@@ -33,6 +33,7 @@ export default (resolvers = {}, config = {}) => {
};
return new ApolloClient({
typeDefs: config.typeDefs,
link: ApolloLink.split(
operation => operation.getContext().hasUpload || operation.getContext().isSingleRequest,
createUploadLink(httpOptions),
......
import Vue from 'vue';
import VueApollo from 'vue-apollo';
import createDefaultClient from '~/lib/graphql';
import typeDefs from './typedefs.graphql';
Vue.use(VueApollo);
const createApolloProvider = data => {
const defaultClient = createDefaultClient(
{},
{
typeDefs,
},
);
defaultClient.cache.writeData({
data,
});
return new VueApollo({
defaultClient,
});
};
export default createApolloProvider;
extend type Query {
isSupportedContent: Boolean!
projectId: String!
returnUrl: String
sourcePath: String!
username: String!
}
......@@ -3,9 +3,12 @@ import { parseBoolean } from '~/lib/utils/common_utils';
import App from './components/app.vue';
import createStore from './store';
import createRouter from './router';
import createApolloProvider from './graphql';
const initStaticSiteEditor = el => {
const { isSupportedContent, projectId, path: sourcePath, returnUrl, baseUrl } = el.dataset;
const { isSupportedContent, projectId, path: sourcePath, baseUrl } = el.dataset;
const { current_username: username } = window.gon;
const returnUrl = el.dataset.returnUrl || null;
const store = createStore({
initialState: {
......@@ -13,15 +16,23 @@ const initStaticSiteEditor = el => {
projectId,
returnUrl,
sourcePath,
username: window.gon.current_username,
username,
},
});
const router = createRouter(baseUrl);
const apolloProvider = createApolloProvider({
isSupportedContent: parseBoolean(isSupportedContent),
projectId,
returnUrl,
sourcePath,
username,
});
return new Vue({
el,
store,
router,
apolloProvider,
components: {
App,
},
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment