Last active
March 31, 2018 13:09
-
-
Save tgmarinho/ea8ee580486b05ca5d5a4e9acdf04fdc to your computer and use it in GitHub Desktop.
High Order Function -> Form of forms!
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
import { graphql } from 'react-apollo'; | |
import gql from 'graphql-tag'; | |
import { withForm } from './withForm'; | |
import { AddTask } from '../ui/AddTask'; | |
export const addTaskMutation = graphql( | |
gql` | |
mutation addTask($task: AddTaskInput!) { | |
addTask(task: $task) { | |
_id | |
description | |
details | |
} | |
} | |
`, | |
{ | |
name: 'addTask', | |
} | |
); | |
const taskQuery = gql` | |
query Task($taskId: ID!) { | |
task(_id: $taskId) { | |
_id | |
description | |
details | |
dueDate | |
} | |
} | |
`; | |
const data = graphql(taskQuery, { | |
skip: ownProps => !ownProps.match.params._id, | |
options: ownProps => ({ variables: { taskId: ownProps.match.params._id } }), | |
}); | |
export const AddTaskContainer = withForm(AddTask, addTaskMutation, data); |
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
import { withRouter } from 'react-router-dom'; | |
import { withAlert } from '@codeftw/future-web-ui-alert'; | |
import { withContext, withState, compose } from 'recompose'; | |
import { withApollo } from 'react-apollo'; | |
export const withForm = (Component, ...args) => { | |
return compose( | |
withRouter, | |
withApollo, | |
withAlert, | |
...args | |
)(Component); | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment