Open rodrigogs opened 3 weeks ago
I could make it work by stringifying the JSON:
eg.:
async createEvent(createInput: CreateEventInput): Promise<Event> {
return this.client.graphql({
query: createEvent,
variables: {
input: {
...createInput,
involvedPeople: JSON.stringify(createInput.involvedPeople),
},
},
}).then(({ data }) => data.createEvent)
}
Given that the GraphQL schema specifies an array, it's logical to anticipate that the generated input would require an array and not a string. Ignoring the type error in the code might be a temporary workaround, but inherently, it doesn't seem appropriate.
Hi @rodrigogs this seems to be expected behavior. At this point, serialization of the data is up to the client. If you would like for the library to handle serialization, I would recommend opening a feature request.
Hi @chrisbonifacio, I appreciate your response, but I must respectfully disagree with the notion that this is expected behavior. The inconsistency arises because the library's generated GraphQL types specify an array for AWSJSON
fields, yet the underlying system only accepts a stringified JSON, which leads to confusion and the need for additional client-side handling that one could argue should be intrinsic to the library's functionality.
If the intent is indeed for clients to handle serialization, it would be beneficial for this to be explicitly documented, or better yet, for the type generation to align more closely with the actual data expectations—either by correcting the type definitions or by handling serialization/deserialization within the library itself. This would enhance developer experience and reduce potential errors. Would you consider revisiting this issue in light of this perspective?
Before opening, please confirm:
JavaScript Framework
Vue
Amplify APIs
GraphQL API
Amplify Version
v6
Amplify Categories
api
Backend
Amplify CLI
Environment information
Describe the bug
I'm developing an application using Nuxt 3 and Amplify.
I created a data model using Ampify Studio:
I configured Amplify in my application: .graphqlconfig.yml
plugins/aws-amplify.ts
When sending empty JSONs, it works. But when I have any items I get
{ data: null, errors: [ { path: null, locations: [Array], message: "Variable 'involvedPeople' has an invalid value." } ] }
dao.tsExpected behavior
I should be able to send a JSON with items to the backend through the graphql API.
Reproduction steps
Code Snippet
Log output
aws-exports.js
Manual configuration
No response
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response