I’m working with AWS Amplify Gen 2 and have defined a GraphQL mutation that accepts an array of objects. However, I’m encountering issues when sending the array from my client mutation.
Here’s my schema definition:
import { a } from "@aws-amplify/backend";
import { POAcknowledgementCreationFunction } from "../../../functions/POAcknowledgementCreation/resource";
export const POAcknowledgementCreationSchema = {
// Define the Supplier POAcknowledgement Creation mutation
CreatePOAcknowledgement: a
.mutation()
.arguments({
input: a.ref("SupplierPOAcknowledgementInput").required(), // ✅ This is valid in custom types
})
.returns(a.ref("SupplierPOAcknowledgementCreationResponse"))
.authorization((allow) => [allow.groups(["Suppliers"])])
.handler(a.handler.function(POAcknowledgementCreationFunction)),
SupplierPOAcknowledgementInput: a.customType({
PurchaseOrderID: a.string().required(),
PurchaseOrdeItem: a.ref('PurchaseOrderItemInput').array().required(),
}),
PurchaseOrderItemInput: a.customType({
PurchaseOrderItemID: a.string().required(),
ConfirmedItem: a.ref('ConfirmedItemInput').array().required(),
}),
ConfirmedItemInput: a.customType({
DeliveryDate: a.string().required(),
ConfirmedQuantity: a.integer().required(),
ConfirmedQuantityUOM: a.string().required(),
}),
// Response Type for SupplierPOAcknowledgementInput
SupplierPOAcknowledgementCreationResponse: a.customType({
SupplierPOAcknowledgementStatus: a.string().required(),
}),
};
Mutation I’m Trying:
mutation MyMutation {
CreatePOAcknowledgement(
input:
{
PurchaseOrderID: "12345",
PurchaseOrdeItem:
[
{
PurchaseOrderItemID: "12345",
ConfirmedItem:
{
DeliveryDate: "12365",
ConfirmedQuantity: 10,
ConfirmedQuantityUOM: "EA"
}
}
]
}
) {
SupplierPOAcknowledgementStatus
}
}
When I run this mutation, I’m getting a validation or type mismatch error indicating that the array input isn’t being parsed correctly.
Is there a specific syntax or configuration needed in Amplify Gen 2 for accepting array inputs in custom mutations?
Any guidance or clarification on how to correctly define and send an array of objects in Amplify Gen 2 would be greatly appreciated.