Adds graph functionality for plugins

This commit is contained in:
Belen Curcio
2017-03-29 19:11:43 -03:00
parent 4ca2a48bc9
commit 9df334866d
5 changed files with 50 additions and 4 deletions
+3 -1
View File
@@ -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);
+15 -1
View File
@@ -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()
};
@@ -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
}
});
}})
});
@@ -0,0 +1,10 @@
mutation CreateRespect ($respect: CreateRespectInput!) {
createRespect(respect: $respect) {
respect {
id
}
errors {
translation_key
}
}
}
+9 -2
View File
@@ -1,5 +1,12 @@
const typeDefs = require('./server/typeDefs');
module.exports = {
typeDefs
};
typeDefs,
resolvers: {
RootMutation: {
createRespect(_, {respect: {item_id, item_type}}, {mutators: {Action}}) {
return Action.create({item_id, item_type, action_type: 'RESPECT'});
}
}
}
};