samjbmason
07/13/2017, 10:22 PMnilan
07/13/2017, 10:24 PMwithApollo
injects a client instance that allows you to create a promise that sends a query. then
-ing the promise gives access to the datanilan
07/13/2017, 10:24 PMprops
, you need to use the graphql
HOC insteadcj
07/13/2017, 10:27 PMsamjbmason
07/13/2017, 10:39 PMhandleSubmit: (payload, { props }) => {
props.client
.query({
query: findUserQuery,
variables: { email: payload.email }
})
.then(({ data }) => {
if (data.User != null) {
return props.client.mutate({
mutation: createRideWithExistingUserMutation,
variables: { userId: data.User.id, ...rideObject(payload) }
})
}
return props.client.mutate({
mutation: createUserAndRideMutation,
variables: { email: payload.email, ...rideObject(payload) }
})
})
.catch(e => console.log(e))
}
samjbmason
07/13/2017, 10:39 PMsamjbmason
07/13/2017, 10:46 PMcj
07/13/2017, 11:12 PMgraphql
as @nilan suggested and then do something like:
handleSubmit: async (payload, { props }) => {
const defaultData = { ...rideObject(payload) }
const { User } = await props.findUser({ email: payload.email })
if (User) {
return props.createRideWithExistingUser({ userId: User.id, ...defaultData })
} else {
return props.createUserAndRide({ email: payload.email, ...defaultData })
}
}
cj
07/13/2017, 11:13 PMsamjbmason
07/13/2017, 11:30 PMconst { User } = await props.findUser({ email: payload.email })
cj
07/14/2017, 12:29 AMimport { graphql } from 'react-apollo'
is for http://dev.apollodata.com/react/higher-order-components.htmlsamjbmason
07/14/2017, 6:50 AMsamjbmason
07/14/2017, 6:51 AMsamjbmason
07/14/2017, 7:26 AMwithApollo
HOC for the query and then use graphql
for the mutations therefore being able to access the mutation results in the propsdankent
07/14/2017, 7:50 AMsamjbmason
07/14/2017, 8:56 AMgraphql
so I could use them in the props with props.mutate
and then used the withApollo to setup a props.client.query
to fetch the the user in the submit handler and the pass that value to the mutations. It seemed to work pretty well