What I'm trying to do is to send data from a React Native app through AppSync so that I can update a user's data on a dynamo table. I can perform all of my CRUD operations, just not a list of data. When I try, I get an error that what I'm sending isn't a valid JSON. However, my input passes as valid JSON when I put it through a JSON linter.
To try and solve this problem, I've changed my input flow to the simplest possible process. Originally I was pulling my JSON from a parsed JSON string that was locally cached. I thought that perhaps there was an issue with the JSON.parse(obj) function. That didn't hold up to reason. So I moved all of my input out of a JS object and into a JSON that isn't stored in a variable beforehand but is directly passed to the API I'm using (https://aws-amplify.github.io/docs/js/api).
After this didn't work, I thought that maybe my GraphQL Schema was wrong for the object type I was sending, but didn't find anything amiss.
My schema in AppSync using GraphQL is defined as follow:
input CreateUserInput {
email: String!
data: AWSJSON
}
The request I'm sending is as follows:
const dbReturn = await API.graphql(graphqlOperation(
mutations.createUser, {
input: {
"email": "[email protected]",
"data": [{
"num": 34,
}]
}
}
));
The error message says:
"Variable 'data' has an invalid value. Unable to parse [{num=34}] as valid JSON."
What confuses me is that "[{num=34}]"
isn't the input I'm giving it. I'm sending it "[{"num": 34}]"
which is valid JSON. I would expect it to be able to parse my input and send the data to my dynamo table seeing as the JSON input is valid.
Anybody have any ideas what I can do to get past this? Thank you for the help!