Add first mutation

This commit is contained in:
Ramon Wenger 2018-09-11 10:10:42 +02:00
parent 424e1c7f48
commit f3a383d8dd
4 changed files with 23 additions and 1 deletions

View File

@ -122,7 +122,7 @@
saveContentBlock() { saveContentBlock() {
this.$store.dispatch('saveContentBlock', { this.$store.dispatch('saveContentBlock', {
title: this.title, title: this.title,
elements: this.elements contents: this.elements
}); });
} }
}, },

View File

@ -1,5 +1,8 @@
import Vue from 'vue' import Vue from 'vue'
import Vuex from 'vuex' import Vuex from 'vuex'
import apolloClient from '@/graphql/client'
import NEW_CONTENT_BLOCK_MUTATION from '@/graphql/gql/mutations/addContentBlock.gql';
Vue.use(Vuex) Vue.use(Vuex)
@ -36,6 +39,23 @@ export default new Vuex.Store({
}, },
saveContentBlock({commit, dispatch}, payload) { saveContentBlock({commit, dispatch}, payload) {
commit('setNewContentBlock', payload); commit('setNewContentBlock', payload);
apolloClient.mutate({
mutation: NEW_CONTENT_BLOCK_MUTATION,
variables: {
input: {
contentBlock: {
title: payload.title,
contents: [
{
type: 'text_block',
text: 'Oh hai'
}
]
},
after: 'Q29udGVudEJsb2NrTm9kZToxOQ=='
}
}
});
dispatch('hideModal'); dispatch('hideModal');
} }
}, },

View File

@ -128,6 +128,7 @@ class AddContentBlock(relay.ClientIDMutation):
new_contents = handle_content_blocks(contents) # can only do this after the content block has been saved new_contents = handle_content_blocks(contents) # can only do this after the content block has been saved
new_content_block.contents = json.dumps(new_contents) new_content_block.contents = json.dumps(new_contents)
new_content_block.save()
return new_content_block return new_content_block

View File

@ -46,6 +46,7 @@ class NewContentBlockMutationTest(TestCase):
new_content_block = result.get('data').get('addContentBlock').get('newContentBlock') new_content_block = result.get('data').get('addContentBlock').get('newContentBlock')
self.assertEqual(new_content_block.get('title'), title) self.assertEqual(new_content_block.get('title'), title)
self.assertEqual(len(new_content_block['contents']), 1)
id = new_content_block.get('id') id = new_content_block.get('id')
content_block_page = get_object(ContentBlock, id) content_block_page = get_object(ContentBlock, id)