I have a datasheet style table with list of records, that need updating their values. I would like to run a single Submit and in my GraphQL send an array of records as a single argument to the set query. They are actually MongoDB documents. As in the title I am using React with Apollo client. Thank you in advance :)
More details below
So I have this mutation on server side it works with Playground. However it gives errors on Apollo client side.
mutation { updateWorklogs( input: [ { id: "60c6b", week1: 1, week2: 2, week4: 9 }, { id: "60c6c", week1: 3, week2: 4, week4: 1.5 } ] ) { id year month name } }
Apollo Client tools show the mutation variables correctly as
However in Apollo Client tools when I try to run the query it is showing as {“input”:[{“id”:“60c6b9ca277c815ec200992a”,“week1”:5,“week2”:2,“week3”:0,“week4”:9},{“id”:“60c6ba80277c815ec200992e”,“week1”:0,“week2”:5,“week3”:0,“week4”:0}]}
which I guess is fine. This should work as it is identical to what I'm running in Playground, but not!
I tried to run JSON.parse(myVariables) but no help. Apollo seems to convert it. And final result the query doesn’t run. It returns a 400 response, with not much else. If I need an interface I'm not using TS, no idea how to do it in React JS yet.
const [setWorklog] = useMutation(SET_WORKLOGS);
const handleSubmit = (event) => {
event.preventDefault();
console.log("state=", state) // returns the above state, which is correct
setWorklog({ variables: { input: state }, update(proxy, result) {
const data = proxy.readQuery({
query: GET_WORKLOGS
})
data.userWorklogs = result.data.setWorklogs;
proxy.writeQuery({ query: GET_WORKLOGS, data });
}}).then(
console.log("returned=",data.updateWorklogs)
)
.catch(e => {
console.log("Error=", e);
})
};
Thanks again