GraphQl上的无反应突变

发布于 2025-02-12 17:42:30 字数 3595 浏览 1 评论 0原文

当我对USEMUNTING注入值时,它会给我错误400 140。数据类型确实匹配。在“ timporment_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
    }
  }
}

它返回了Null tiviment_booking的错误

但是当查看django admin时,创建的数据出现

在这里我的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
  }
}
`;

,这是我的usemuoning挂钩

const [CreateVideoConsultation] = useMutation(CREATE_VIDEO_CONSULTATION);
CreateVideoConsultation({
                variables:{
                    client: sched.appointmentBooking.client.username,
                    veterinarian: sched.appointmentBooking.veterinarian.username,
                    appointment_booking: parseInt(sched.appointmentBooking.id)
                }
            })

这些是我遇到的错误的预览

When I am injecting values on useMutation it gives me Error 400 140. The data types does match. In appointment_booking argument, I am passing the its ID as a reference on the other table.
Here is my Schema

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)

Here is my model

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)

Here is my mutation in 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
    }
  }
}

It returns an error with null appointment_booking
enter image description here

But when look at the django admin the data created appears

Here my 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
  }
}
`;

and Here is my useMutation Hook

const [CreateVideoConsultation] = useMutation(CREATE_VIDEO_CONSULTATION);
CreateVideoConsultation({
                variables:{
                    client: sched.appointmentBooking.client.username,
                    veterinarian: sched.appointmentBooking.veterinarian.username,
                    appointment_booking: parseInt(sched.appointmentBooking.id)
                }
            })

These are the preview of errors that I am getting
enter image description here

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

も让我眼熟你 2025-02-19 17:42:30

这是我的错误,我忘记了我在石墨烯突变中使用的所有蛇形案例变量都成为阿波罗的骆驼盒。例如,create_video_consultation成为createvideoconcultation ...

It was my mistake I forgot that all of the snake case variables that I have use in graphene mutation becomes camel case in apollo. For example create_video_consultation becomes createVideoConsultation...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文