I am a newbie here. What I am trying to do is
1\ Use Error Transformer (on a GraphQL query/mutation) to return the error message
2\ Get the error message in Javascript query, which calls the GraphQL query/mutation, and display the error message in a text widget.
From console output, I can see that the Error Transform does retrieve the error message; however, what the Javascript query gets is way more than the error message, such as metadata ... For example,
{"data":{"data":{"xxx":{"addUser":{"id":"yyy","message":"zzz"},"user":null}},"metadata": ....}
Shouldn't I get the message "zzz" only ? Anything I misunderstand or miss about Error Transformer? Please HELP!
The Error Transformer is as follows (xxx is GraphQL query/mutation name)
if (Array.isArray(errors) && errors.length > 0) {
return errors[0].message;
} else if (data.addUser.error) {
console.log(data.addUser.error.message)
return data.addUser.error.message;
} else {
return false;
}
The Javascript query that calls GraphQL query/mutation is as follows
...
return addUser.trigger({
additionalScope: {input: input},
onSuccess: (data) => {
...
},
onFailure: (error) => {
console.log(error);
},
});