Skip to content

Instantly share code, notes, and snippets.

@SachaG
Created April 14, 2017 04:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SachaG/188b6b9058852066d623879464c278a1 to your computer and use it in GitHub Desktop.
Save SachaG/188b6b9058852066d623879464c278a1 to your computer and use it in GitHub Desktop.
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