Безответная мутация на graphql
Когда я ввожу значения на useMutation, он выдает мне ошибку 400 140. Типы данных совпадают. В аргументе appointment_booking я передаю его ID как ссылку на другую таблицу. Вот моя схема
class CreateVideoConsultation(graphene.Mutation):
id = graphene.Int()
client = graphene.String()
veterinarian = graphene.String()
appointment_booking = graphene.Int()
class Arguments:
client = graphene.String()
veterinarian = graphene.String()
appointment_booking = graphene.Int()
def mutate(self, info, client, veterinarian, appointment_booking):
client_username = Client.objects.get(username = client)
veterinarian_username = Veterinarian.objects.get(username = veterinarian)
appointment_booking_id = Appointment_Booking.objects.get(id = appointment_booking)
video_consultation = Video_Consultation(client = client_username, veterinarian = veterinarian_username, appointment_booking = appointment_booking_id)
video_consultation.save()
return CreateVideoConsultation(id = video_consultation.id, client = client_username, veterinarian = veterinarian_username, appointment_booking = appointment_booking_id)
class Mutation (graphene.ObjectType):
create_video_consultation = CreateVideoConsultation.Field()
schema = graphene.Schema(query = Query, mutation = Mutation)
Вот моя модель
class Video_Consultation(models.Model):
client = models.ForeignKey('Client', on_delete = models.DO_NOTHING)
veterinarian = models.ForeignKey('Veterinarian', on_delete = models.DO_NOTHING)
appointment_booking = models.ForeignKey('Appointment_Booking', on_delete = models.DO_NOTHING)
def __str__(self):
return str(self.client)
Вот моя мутация в Graphiql
mutation{
createVideoConsultation(client:"GGGG",veterinarian:"Peppermint",appointmentBooking:29){
id
client
veterinarian
appointmentBooking
}
}
{
"errors": [
{
"message": "int() argument must be a string, a bytes-like object or a real number, not 'Appointment_Booking'"
}
],
"data": {
"createVideoConsultation": {
"id": 7,
"client": "GGGG",
"veterinarian": "Peppermint",
"appointmentBooking": null
}
}
}
Выдает ошибку с нулевым значением appointment_booking
Но при просмотре в админке django созданные данные отображаются
Вот мой gql
export const CREATE_VIDEO_CONSULTATION = gql`
mutation createVideoConsultation($client:String!,$veterinarian:String!,$appointmentBooking:Int!){
createVideoConsultation(client:$client,veterinarian:$veterinarian,appointmentBooking:$appointmentBooking){
id
client
veterinarian
appointmentBooking
}
}
`;
и вот мой хук useMutation
const [CreateVideoConsultation] = useMutation(CREATE_VIDEO_CONSULTATION);
CreateVideoConsultation({
variables:{
client: sched.appointmentBooking.client.username,
veterinarian: sched.appointmentBooking.veterinarian.username,
appointment_booking: parseInt(sched.appointmentBooking.id)
}
})
Вот предварительный просмотр ошибок, которые я получаю
Это была моя ошибка, я забыл, что все переменные змеиного регистра, которые я использовал в графеновой мутации, становятся верблюжьим регистром в apollo. Например, create_video_consultation становится createVideoConsultation...