Title: Submit graphql mutation containing nested array of object playload with "aws-amplify"
Tags: javascript;graphql;aws-amplify
Question: I trying to submit below payload (nested array of objects) using aws-amplify:
"data": [
{ "name": "alpha", "description": "lorem" },
{ "name": "bravo", "description": "ipsum" },
This solution (source code is TypeScript):
import AWSAmplifyAPI, { graphqlOperation } from "@aws-amplify/api";
const rawGraphQLRequest: string = `
mutation ($data: [registerMultipleItemsInput]!) {
registerMultipleItems(data: [$data])
type Item = {
name: string;
description: string;
async function registerMultipleItems(items: Array<Item&gt;): Promise<void&gt; {
await AWSAmplifyAPI.graphql(graphqlOperation(rawGraphQLRequest, { data: items }));
causes unclear error:
Validation error of type VariableTypeMismatch: Variable type '[registerMultipleItemsInput]!' doesn't match expected
type 'registerMultipleItemsInput' @ 'registerMultipleItems'";
Is backend, the scheme defined as:
registerMultipleItems(data: [registerMultipleItemsInput]!): [String]!
@aws_cognito_user_pools
input registerMultipleItemsInput{
name: String!
description: String!
I tried to add registerMultipleItemsInput definition to rawGraphQLRequest:
const rawGraphQLRequest: string = `
input registerMultipleItemsInput {
name: String!
description: String!
mutation ($data: [registerMultipleItemsInput]!) {
registerMultipleItems(data: [$data])
Above error left, and additional error occurred:
Validation error of type NonExecutableDefinition: The registerMultipleItemsInput definition is not executable.
What the correct syntax for { "data": <Array&gt; } payload?
P. S. I hope I don't need to define registerMultipleItemsInput in rawGraphQLRequest, because registerMultipleItemsInput already has been defined in backend and defining it again in frontend is some kind of hardcoding.

Here is the accepted answer: I think your first solution is correct except for:
mutation ($data: [registerMultipleItemsInput]!) {
registerMultipleItems(data: [$data]) // <-------- incorrect
$data already contains an array of registerMultipleItemsInput but you've wrapped it in another array which is incorrect, it must be:
mutation ($data: [registerMultipleItemsInput]!) {
registerMultipleItems(data: $data) // <-------- correct


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2020:00:03/04/20', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<javascript><graphql><aws-amplify>', 'Title': 'Submit graphql mutation containing nested array of object playload with "aws-amplify"', 'ViewCount': 579, 'id': 60522485, 'user_AboutMe': '<p>Since Japanese naturalization, Takeshi Tokugawa is my official name.</p>\n<p>TypeScript/Vue/NestJS-focused full-stack engineer.\nCurrently the sole proprietorship with business name &quot;Yamato Daiwa&quot;.</p>\n<p>The author of:</p>\n<ul>\n<li><p><a href="https://github.com/TokugawaTakeshi/Yamato-Daiwa-ES-Extensions/blob/master/CoreLibrary/Package/README.md" rel="nofollow noreferrer">Yamato-Daiwa ES-Extensions</a>: Helper functions and classes aimed to reduce the routine code. Build-in TypeScript type safety without <code>any</code> type.</p>\n</li>\n<li><p><a href="https://github.com/TokugawaTakeshi/Yamato-Daiwa-Frontend/blob/master/CoreLibrary/Package/README.md" rel="nofollow noreferrer">Yamato-Daiwa Frontend</a>: The toolkit for the frontend development with Pug and Stylus pre-processors.</p>\n</li>\n<li><p><a href="https://github.com/TokugawaTakeshi/Yamato-Daiwa-Backend/blob/master/MainPackage/README.md" rel="nofollow noreferrer">Yamato-Daiwa Backend</a> The back-end framework (currently in the early stage of development)</p>\n</li>\n</ul>\n<p>Also, I am developing the <strong>Yamato-Daiwa Automation</strong>, the tool for the projects building and deploying targeting to <code>Pug</code>, <code>Stylus</code> and <code>TypeScript</code> users (no source code has been published yet).</p>\n<p>Learning the .NET MAUI to extend my specialty until native applications development.</p>\n', 'user_AccountId': 2816973.0, 'user_DisplayName': 'Takeshi Tokugawa YD', 'user_Reputation': 169.0, 'user_Views': 1171.0, 'user_id': 4818123.0}}