Мутация Django-Graphql работает в Playground, но возвращает null в ReactJS-Apollo
Я делаю простую мутацию обновления из Graphql Playground, и я считаю, что если мутация работает из playground, следовательно, нет проблем в бэкенде.
mutation{
emwCustomMessageToCustomerUpdate(
id:"RU1XQ3VzdG9tSW5mb3JtYXRpb25Gb3JDdXN0b21lcjoxNQ==",
input:{
isActive:false,
allowClose:false,
message:"asdfssdf",
displayLocation:"S1",
messageHeader:"Dsfsdf"
}){
eMWInformationForCheckout{
message
}
errors{
message
}
}
}
Который возвращает этот ответ, указывающий на успешность вызова, я могу проверить это.
{
"data": {
"emwCustomMessageToCustomerUpdate": {
"eMWInformationForCheckout": {
"message": "asdfssdf"
},
"errors": []
}
}
}
Но когда я вызываю эту мутацию из reactjs-apollo, она не изменяет данные, Я изменяю один ключ, но другие ключи становятся нулевыми. Мутация, которую я использую из react, выглядит следующим образом :
export const UpdateMessageForCustomer = gql`
mutation UpdateMessageForCustomer(
$id: ID!
$message: String
$startDate: DateTime
$endDate: DateTime
$allowClose: Boolean
$displayLocation : String
$buttonText : String
$screenPlacement : String
$messageHeader : String
$isActive : Boolean
){
emwCustomMessageToCustomerUpdate(id: $id,
input:{
message: $message
startDate: $startDate,
endDate: $endDate,
allowClose: $allowClose,
displayLocation : $displayLocation
buttonText : $buttonText
screenPlacement : $screenPlacement
messageHeader : $messageHeader
isActive : $isActive
}){
eMWInformationForCheckout{
message
}
errors{
message
}
}
}
`
функция, используемая для мутации в компоненте react
const [UpdateMessageForCustomerMutation] = useMutation(UpdateMessageForCustomer, {
onCompleted({ emwCustomMessageToCustomerUpdate }) {
if (emwCustomMessageToCustomerUpdate.errors.length) {
notify({
text: intl.formatMessage({
defaultMessage: "Message added successfully"
})
});
refetch()
}
},
onError(error) {
console.log('error', error)
}
});
и мутация триггера следующая
const changeMessageStatus = (e, id) => {
UpdateMessageForCustomerMutation({
variables: {
id : id,
input : {
[e.target.name]:e.target.value
}
}
})
}
Это было очень просто, Мне просто нужно было отправить все переменные в объект "variables" напрямую, Вложение их внутри переменной "input" делало входные данные нулевыми, потому что graphql ожидал их в переменных. Я не уверен как, но в бэкенде они определенно приходят в объект "input", вот почему я толкал их таким образом.
Спасибо.