How to get node after update without a new query

I want to get the node after a mutation. it’s my code:

        var updates = map[string]interface{}{
                "foo": "bar",
        }
        updates["uid"] = uid
	updates["metadata.update_time"] = time.Now().Unix()
	bs, err := json.Marshal(updates)
	if err != nil {
		return nil, err
	}

	_, err = dg.mutationJSON(ctx, bs)   // it's a mutation
	if err != nil {
		return nil, err
	}

	node, err = dg.queryByUID(ctx, uid) // after mutation, get the new node

Are there any way get the node after a mutation without query?

“Get the node” is actually “query for a node”, so either you query/get it, or you use your locally cached node (but then you don’t know if somebody else has changed it or not). So the simple answer would be “no”.

3 Likes

In the GraphQL API which is rewritten to DQL logic, it is doing a mutation and then a query. This also appeases the case when the query expects more data than the mutation. Example, if you link a new post to an existing user but in the response you want the query to return the authors other recent posts uids as well.

2 Likes

thanks