CodexBloom - Programming Q&A Platform

AWS AppSync Resolver Mapping Template scenarios with 'Invalid JSON' scenarios on Mutations with Nested Inputs

👀 Views: 3 đŸ’Ŧ Answers: 1 📅 Created: 2025-06-06
aws appsync graphql

I'm wondering if anyone has experience with I'm building a feature where I've searched everywhere and can't find a clear answer... I'm currently working on an AWS AppSync API and working with an scenario when trying to execute mutations that involve nested input objects. Despite having the correct schema set up, I'm receiving an behavior that says `"Invalid JSON"` when I try to pass a nested input like the following: ```json { "input": { "name": "John Doe", "address": { "street": "123 Main St", "city": "Anytown" } } } ``` My mutation is defined in the schema as: ```graphql input AddressInput { street: String! city: String! } input UserInput { name: String! address: AddressInput! } type Mutation { createUser(input: UserInput!): User } ``` When I call the mutation using the AWS AppSync console, I ensure the JSON is valid, but still face this scenario. I've checked the mapping templates for the resolver, and they are quite straightforward. My VTL mapping template for the mutation is: ```vtl ## mutation request mapping template { "version": "2018-05-29", "operation": "PutItem", "key": { "PK": { "S": "USER#${ctx.args.input.name}" }, "SK": { "S": "PROFILE" } }, "attributeValues": { "name": { "S": "${ctx.args.input.name}" }, "address": { "M": { "street": { "S": "${ctx.args.input.address.street}" }, "city": { "S": "${ctx.args.input.address.city}" } }} } } ``` I have verified that the mapping template syntax is correct and that the input structure aligns with the expected schema. The scenario appears to be with how the nested attributes are handled. I've tried adjusting the mapping template to use `toJson` and `toMap` functions but it still results in the same behavior. Has anyone encountered a similar scenario when dealing with nested inputs in AppSync, and how can I resolve the 'Invalid JSON' behavior? Any insights on the proper structure for nested inputs in AppSync mutations would be greatly appreciated. I'm working on a application that needs to handle this. For context: I'm using Graphql on Windows. What am I doing wrong? The stack includes Graphql and several other technologies. Thanks, I really appreciate it!