diff --git a/client/coral-embed-stream/src/Embed.js b/client/coral-embed-stream/src/Embed.js index 791f4ef5f..b3244d56b 100644 --- a/client/coral-embed-stream/src/Embed.js +++ b/client/coral-embed-stream/src/Embed.js @@ -5,6 +5,7 @@ import isEqual from 'lodash/isEqual'; import I18n from 'coral-framework/modules/i18n/i18n'; import translations from 'coral-framework/translations'; const lang = new I18n(translations); +import {graphImporter} from 'coral-framework/helpers/importer'; import {TabBar, Tab, TabContent, Spinner} from 'coral-ui'; @@ -277,5 +278,6 @@ export default compose( addCommentTag, removeCommentTag, deleteAction, - queryStream + queryStream, + ...graphImporter )(Embed); diff --git a/client/coral-framework/helpers/importer.js b/client/coral-framework/helpers/importer.js index 904673075..de031a744 100644 --- a/client/coral-framework/helpers/importer.js +++ b/client/coral-framework/helpers/importer.js @@ -103,9 +103,23 @@ function reducersImporter () { return importAll(require.context('plugins', true, /\.\/(.*)\/client\/reducer.js$/)); } +function graphImporter () { + const context = require.context('plugins', true, /\.\/(.*)\/client\/(queries|mutations)\/index.js$/); + return context + .keys() + .map(key => shapeData(key)) + .reduce((entry, actionsPlugin) => { + const input = context(actionsPlugin.key); + const res = Object.keys(input) + .map(key => input[key]); + return [...entry, ...res]; + }, []); +} + export default { importer, actionsImporter: actionsImporter(), - reducersImporter: reducersImporter() + reducersImporter: reducersImporter(), + graphImporter: graphImporter() }; diff --git a/plugins/coral-plugin-respect/client/mutations/index.js b/plugins/coral-plugin-respect/client/mutations/index.js new file mode 100644 index 000000000..9b78ee40c --- /dev/null +++ b/plugins/coral-plugin-respect/client/mutations/index.js @@ -0,0 +1,13 @@ +import {graphql} from 'react-apollo'; +import POST_RESPECT from './postRespect.graphql'; + +export const postRespect = graphql(POST_RESPECT, { + props: ({mutate}) => ({ + postRespect: (respect) => { + return mutate({ + variables: { + respect + } + }); + }}) +}); diff --git a/plugins/coral-plugin-respect/client/mutations/postRespect.graphql b/plugins/coral-plugin-respect/client/mutations/postRespect.graphql new file mode 100644 index 000000000..a7edc97e3 --- /dev/null +++ b/plugins/coral-plugin-respect/client/mutations/postRespect.graphql @@ -0,0 +1,10 @@ +mutation CreateRespect ($respect: CreateRespectInput!) { + createRespect(respect: $respect) { + respect { + id + } + errors { + translation_key + } + } +} diff --git a/plugins/coral-plugin-respect/index.js b/plugins/coral-plugin-respect/index.js index bd87e11d7..915d14ac0 100644 --- a/plugins/coral-plugin-respect/index.js +++ b/plugins/coral-plugin-respect/index.js @@ -1,5 +1,12 @@ const typeDefs = require('./server/typeDefs'); module.exports = { - typeDefs -}; \ No newline at end of file + typeDefs, + resolvers: { + RootMutation: { + createRespect(_, {respect: {item_id, item_type}}, {mutators: {Action}}) { + return Action.create({item_id, item_type, action_type: 'RESPECT'}); + } + } + } +};