-
Notifications
You must be signed in to change notification settings - Fork 787
Inconsistent state in mapMutationsToProps #41
Comments
Hmm, perhaps we could instead just use the current store state? Rather than initializing a function that includes the state? |
@stubailo we could pass a method to get the state which would give more dynamic options: Option 1const mapMutationsToProps = ({ getState }) => ({
onMutation: () => ({
mutation: `
mutation myAwesomeMutation (
$formKeys: String!
) {
awesomeMutation(
formKeys: $formKeys
) {
passThroughtInput
}
}
`,
variables: {
formKeys: JSON.stringify(Object.keys(getState().form)),
},
})
}); Option 2const mapMutationsToProps = ({ getState }) => {
const state = getState()
if (state.boolValue) {
return { // other mutation }
}
return {
onMutation: () => ({
mutation: `
mutation myAwesomeMutation (
$formKeys: String!
) {
awesomeMutation(
formKeys: $formKeys
) {
passThroughtInput
}
}
`,
variables: {
formKeys: JSON.stringify(Object.keys(getState().form)),
},
})
}
}; |
Hmm, this seems a bit odd and kinda encourages people to start doing interesting stuff with |
@jbaxleyiii I can think in some use cases - like signup vs login w/ username vs login w/ email - that I would be tempted to put the logic there like the Option 2. But I think should be better to just have a function that do these logic and call the correct static mutation. @stubailo Vote for keeping the initial proposed API Also, the |
Originally posted by @deoqc on apollo-client:
I am using redux-form and have 2 forms (lets say FormA and FormB, 'living' in
state.form.FormA
andstate.form.FormB
).The problem is that
FormB
is not always showing in the state when usingmapMutationsToProps
, but it is correct inmapStateToProps
or in the store (as shown by devtools).To be more precise, my code is something like this:
and the mutation only returns the same input (
passThroughtInput === formKeys
)To check, I also have the following:
The callback to the
onMutation
prints the results on console, and theformKeys
is in aText
tag on screen, and also using devtools (so I compare the 3).As said before, mapStateToProps and store devtools are correct. Mutation is missing (at least most of the time) the state.FormB key (but showing state.FormA).
If you guys don't have any clues, I can try to do a reproducible repo.
The text was updated successfully, but these errors were encountered: