Created
April 14, 2017 04:07
-
-
Save SachaG/188b6b9058852066d623879464c278a1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function withMutation({name, args}) { | |
let mutation; | |
if (args) { | |
const args1 = _.map(args, (type, name) => `$${name}: ${type}`); // e.g. $url: String | |
const args2 = _.map(args, (type, name) => `${name}: $${name}`); // e.g. $url: url | |
mutation = ` | |
mutation ${name}(${args1}) { | |
${name}(${args2}) | |
} | |
` | |
} else { | |
mutation = ` | |
mutation ${name} { | |
${name} | |
} | |
` | |
} | |
return graphql(gql`${mutation}`, { | |
props: ({ownProps, mutate}) => ({ | |
[name]: (vars) => { | |
return mutate({ | |
variables: vars, | |
}); | |
} | |
}), | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment