ParseReact
ParseReact copied to clipboard
Issues updating query after mutation
I have the following query that I would like to automatically update after I do a create mutation:
var Group = Parse.Object.extend("Group");
observe(props, state) {
var groupObject = new Group();
groupObject.id = props.selectedGroupId;
var agentQuery = new Parse.Query(Agent);
agentQuery.equalTo("group", groupObject);
return {agents: agentQuery};
},
When I do the following mutation, as seen in the parse javascript sdk docs, it properly creates the row in the back-end, but it doesn't trigger a react UI update:
var groupObject = new Group();
groupObject.id = groupId;
ParseReact.Mutation.Create("Agent", {
name: name,
group: groupObject
}).dispatch({waitForServer: true});
Looking at QueryTools.js, I tried changing the mutation to the following, and the query immediately updated in the UI:
var groupObject = new Group();
groupObject.id = groupId;
groupObject.objectId = groupId;
groupObject.className = 'Group';
ParseReact.Mutation.Create("Agent", {
name: namee,
group: groupObject
}).dispatch({waitForServer: true});
But this doesn't look like standard practice. What is the recommended way to dispatch a create mutation like the example I have?
Is anyone else able to get queries with equalTo pointers to update? It's pretty suboptimal to have to always manually refresh queries after mutations. @andrewimm any ideas?
Great! I am having this issue also! I have to manually call refreshQueries after dispatch.
Ping @andrewimm does this functionality currently work for anyone or is this a known issue with parse-react?
In the Parse + React shared chemistry blog post you mention this capability when you demonstrate mutating observed objects:
A mutation is applied to an object and dispatched, and the result will be immediately available to components with subscriptions.
However, in practice, we are having a hard time actually having it work. It seems like observed queries are not updated after mutation dispatch and we must manually refresh them.
Thank you for reporting this issue and appreciate your patience. We've notified the core team for an update on this issue. We're looking for a response within the next 30 days or the issue may be closed.
I'm having the exact same problem with using .equalTo
with a Pointer
. I'm really hoping for a fix to this.
I'm having the same problem here. Here's some example code I'm using:
//observe DealComments that have the Deal as its parent
observe: function(props, state){
var self = this;
return {
dealComments: (new Parse.Query('DealComment')).equalTo( 'deal', self.props.deal ).ascending('createdAt')
}
},
Then, I have an "addComment" function that gets invoked on a user action:
addComment: function( comment )
{
var component = this;
ParseReact.Mutation.Create('DealComment', comment)
.dispatch({waitForServer: true})
.then(function(c){
console.log("successfully saved comment");
// component.refreshQueries('dealComments');
});
},
Notice the commented out component.refreshQueries()
call in the addComment()
function. If I uncomment the call to refresh queries, I see my component update. When I leave it commented out as it is here, my component does not update.
I can also confirm that the "workaround" suggested by mikemintz in the original post works for me (i.e. explicitly setting the Object.objectId = Object.id
before dispatching the mutation)