Update 2018: The Apollo 2.1 client has added a new Mutation component that adds the download property back. See @ robin-wieruch's answer below and the announcement here https://dev-blog.apollodata.com/introduction-react-apollo-2-1-c837cc23d926 Read the original question, which now only applies to earlier versions of Apollo.
Using the current graphql version of higher order graphql in graphql react-apollo (v0.5.2), I don't see a documented way to inform my user interface that the mutation is waiting for a server response. I see that earlier versions of the package sent a property indicating the download.
Requests still get the download property, as described here: http://dev.apollodata.com/react/queries.html#default-result-props
My application also uses redundancy, so I think one way to do this is to connect my component to redundancy and pass a property to a function that will put my user interface in load state. Then, when I rewrite my graphql mutation into a property, I can make a call to update the redundancy store.
More or less like this:
function Form({ handleSubmit, loading, handleChange, value }) { return ( <form onSubmit={handleSubmit}> <input name="something" value={value} onChange={handleChange} disabled={loading} /> <button type="submit" disabled={loading}> {loading ? 'Loading...' : 'Submit'} </button> </form> ); } const withSubmit = graphql( gql' mutation submit($something : String) { submit(something : $something) { id something } } ', { props: ({ ownProps, mutate }) => ({ async handleSubmit() { ownProps.setLoading(true); try { const result = await mutate(); } catch (err) {
I am curious if there is a more idiomatic approach to informing the user interface that the mutation is "in flight." Thank you
reactjs graphql apollostack
rmarscher
source share