I´ve build the following mutation:
import {
commitMutation,
graphql
} from 'react-relay';
import { ConnectionHandler } from 'relay-runtime';
import environment from '../../../../environment';
const createMutation = graphql`
mutation CompanyMutation($company: CompanyInput!) {
createCompany(data: $company) {
id
}
}
`
export const createCompany = (company, callback) => {
const variables = {
company: company
}
console.log("Will call mutation");
commitMutation(
environment,
{
createMutation,
variables,
onCompleted: () => {
callback()
},
onError: (error) => {
throw new Error(error)
}
}
)
}
That is called from the following component:
class CompanyForm extends Component {
handleSave = data => {
createCompany(data, () => console.log('COMPANY CREATED'));
};
render = () => {
return (
<Form
onClose={this.handleClose}
onSave={this.handleSave}
/>
);
};
}
export default CompanyForm;
I´m getting the following error:

Is this a bug ? What am I doing wrong in my mutation code ?
@renatonmendes could you provide relay version you're using?
Relay 1.4
Em 25 de out de 2017 21:44, "4a6f616f Gracinha" notifications@github.com
escreveu:
@renatonmendes https://github.com/renatonmendes could you provide relay
version you're using?—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/facebook/relay/issues/2168#issuecomment-339507095,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AJ5LZjpkl5O1hZ3pmtIPSoFW3cBi3498ks5sv8dygaJpZM4QGycc
.
--
*Aviso Legal: *Esta mensagem eletrônica pode conter informações
privilegiadas e/ou confidenciais. Assim, fica o seu receptor, desde já,
expressamente notificado de que qualquer disseminação, distribuição, ou
mesmo a efetivação de cópia não autorizada deste e-mail, é expressamente
proibida. Se você (destinatário da mensagem) entende que recebeu esta
mensagem indevidamente, ou, mesmo por engano, por favor, informe este fato
ao seu remetente, e apague-a imediatamente de seu computador. Outrossim, as
opiniões e/ou informações expressadas neste e-mail pertencem unicamente ao
seu remetente e, não necessariamente, coincidem com àquelas refletidas,
expedidas e/ou determinadas pela Mezasoft.
Legal Notice: This electronic message may contain privileged and/or
confidential information. Therefore, the receiver of this message is
automatically and expressly notified that dissemination, distribution or
unauthorized copies of this email is restricted. If you understand that you
had received that message in error please immediately notify the sender and
delete it from your computer. Moreover, the opinions expressed here are
those of the sender only and do not necessarily coincide with those
determined by Mezasoft.
After console.logging some messages from inside relay code, I´ve found out that the name createMutation is not allowed. As can be seen in line 24 of commitRelayModernMutation.js, it tries to get config.mutation, and in my case I´m using createMutation as the mutation name (it would needed to be then config.createMutation).
I don´t think there is a directive that you should name the mutation variable mutation, so seens to be something strange in the code.
Anyway, in that case, I´m planning to have more than one mutation in this file (createMutation, deleteMutation and editMutation). How can I handle that ?
You could try
commitMutation(
env, {
mutation: myCustomMutationName,
variables,
onCompleted: (response, errors) => {
console.log('Response received from server.')
console.log(response)
},
onError: err => console.error(err),
},
);
Seems to work for me. Thanks for putting me onto it!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Most helpful comment
You could try
commitMutation( env, { mutation: myCustomMutationName, variables, onCompleted: (response, errors) => { console.log('Response received from server.') console.log(response) }, onError: err => console.error(err), }, );Seems to work for me. Thanks for putting me onto it!