I'm new in graphql. I need to perform a mutation using Relay Modern in a React app. According to docs mutation payload can be different from success response to error response. Everything goes fine with success response, but with error response I receive in console this warning:
Warning: RelayResponseNormalizer: Payload did not contain a value for field objectId: objectId
. Check that you are parsing with the same query that was used to fetch the payload.
because error response does not contain objectId field. Apart from that script behave correctly. Here are some samples from docs.. A mutation example:
mutation{
createObject(name: 'john') {
objectId
error
}
}
a success response:
{
"data": {
"createObject": {
"objectId": "123456",
"error": null
}
}
}
and an error response:
{
"data": {
"createObject": {
"error": "[Name should not be Empty]"
}
}
}
This is the code in react component:
const mutation = graphql`
mutation ComponentCreateObjectMutation($name: String) {
createObject(name: $name) {
objectId
error
}
}
`;
commitMutation(
environment,
{
mutation,
variables,
onCompleted: (response, errors) => {
/* error is in response.error */
},
onError: (err) => {...}
}
);
and this is the schema.graphql content:
type ObjectResponse {
objectId: ID,
error: String
}
type Mutation {
createObject(name: String): ObjectResponse
}
What is the best approach to solve this problem? Thanks in advance for your help!