Can anyone help me: I am trying to run the followi...
# orm-help
b
Can anyone help me: I am trying to run the following mutation:
Copy code
mutation {
  updateOrder(
    id: "cjoq8c91d0nb701103qy545x3",
    orderItems: [{
      quantity: 1,
      itemId: "cjollwnqt06o90179wzsqbm7d",
    }]
  ) {
    id
  }
}
My data schema is:
Copy code
type Order @model {
  createdAt: DateTime!
  id: ID! @isUnique
  table: Int!
  orderItems: [OrderItem!]! @relation(name: "OrderItems")
}

type OrderItem @model {
  id: ID! @isUnique
  quantity: Int!
  item: Item! @relation(name: "OrderItem")
  order: Order! @relation(name: "OrderItems")
}
And I keep getting the following error:
Copy code
"message": "Argument 'orderItems' expected type '[OrderorderItemsItem!]' but got: [{quantity: 1, itemId: \"cjollwnqt06o90179wzsqbm7d\"}]. Reason: '[0].quantity' Field 'quantity' is not defined in the input type 'OrderorderItemsItem'. (line 4, column 17):\n orderItems: [{\n ^\n (line 5, column 7):\n quantity: 1,\n ^",
r
For nested mutations we need to use mutation arguments like
create
,
connect
,
disconnect
, etc. Documentation reference: https://www.prisma.io/docs/reference/prisma-api/mutations-ol0yuoz6go#nested-mutations Your mutation should look something like:
Copy code
mutation {
  updateOrder(where: {
    id: "cjoq8c91d0nb701103qy545x3"
  },
  data: {
    orderItems: {
      create: [
        {
          quantity: 1,
          itemId: "cjollwnqt06o90179wzsqbm7d",
        }
      ]
    }
  }) {
    id
  }
}