I have two mutations:
const [createRecord, {data}] = useMutation(createRecordQuery);
which returns the ID of the newly created recordconst [saveValue, {data: dataSave}] = useMutation(saveValueQuery);
which save some values on a record
My saveValue
mutation requires a record ID. If I open my form on a new record, I don't have this ID yet, so on submit I need to call createRecord
first to retrieve the ID and then saveValue
to save values on my record.
This simple approach doesn't work:
const onSave = async values => {
if (!recordId) {
// Call createRecord to retrieve recordId (code is simplified here)
const recordId = await createRecord();
}
// Save my values
return saveValue({variables: {recordId, values});
}
But I don't really know how should I deal with the loading
and data
of the first mutation and wait for it to run the second mutation.
Thanks!