Skip to content

Commit 06490d0

Browse files
committed
add arguments to all actions & add complete readme
1 parent 0a5da8a commit 06490d0

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/index.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import hoistNonReactStatics from 'hoist-non-react-statics';
1010
export { compose } from 'react-apollo';
1111

1212

13+
const prefix = '@@MUTATION/'
14+
15+
1316
function reduxGraphql(options) {
1417
return (Component) => class ReduxGraphql extends React.Component {
1518
render() {
@@ -24,20 +27,23 @@ function reduxGraphql(options) {
2427
const { dispatch } = this.props;
2528
return async (...args) => {
2629
dispatch({
27-
type: options.name |> snakeCase |> toUpper,
30+
type: prefix + options.name |> snakeCase |> toUpper,
2831
payload: args[0],
2932
});
3033
try {
3134
const result = await mutation(...args);
3235
dispatch({
33-
type: options.name + '_success' |> snakeCase |> toUpper,
34-
payload: result,
36+
type: prefix + options.name + '_success' |> snakeCase |> toUpper,
37+
payload: {
38+
result,
39+
args: args[0],
40+
}
3541
});
3642
return result;
3743
}
3844
catch (error) {
3945
dispatch({
40-
type: options.name + '_fail' |> snakeCase |> toUpper,
46+
type: prefix + options.name + '_fail' |> snakeCase |> toUpper,
4147
meta: { error },
4248
});
4349
throw error;

0 commit comments

Comments
 (0)