You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.ts
import{generateClient}from'aws-amplify/api'import{createEvent,updateEvent,deleteEvent}from'~/lib/graphql/mutations'import{getEvent,listEvents}from'~/lib/graphql/queries'importtype{EventPage}from'~/lib/events/model'import{typeEvent,typeCreateEventInput,typeUpdateEventInput,typeDeleteEventInput,EventType}from'~/lib/API'classEventsDAO{privateclientconstructor(){this.client=generateClient()}
...
asynccreateEvent(createInput: CreateEventInput): Promise<Event>{returnawaitthis.client.graphql({query: createEvent,variables: {input: {type: EventType.ECONOMY,title: 'Lorem ipsum dolor sit amet',description: 'Lorem ipsum dolor sit amet',date: '1970-01-01Z',// WORKS!relatedLinks: [],// DOESNT WORK!involvedPeople: ['foo'],involvedOrgs: [],},},}).then(({ data })=>data.createEvent)}
...
}
Expected behavior
I should be able to send a JSON with items to the backend through the graphql API.
Create a schema having some JSON property using Amplify Studio and pull it from the cloud using amplify-cli. Follow Amplify instructions to configure it.
Try to send a JSON with items using the graphql library.
Code Snippet
// Put your code below this line.import{generateClient}from'aws-amplify/api'import{createEvent,updateEvent,deleteEvent}from'~/lib/graphql/mutations'import{getEvent,listEvents}from'~/lib/graphql/queries'importtype{EventPage}from'~/lib/events/model'importtype{EventType,Event,CreateEventInput,UpdateEventInput,DeleteEventInput}from'~/lib/API'classEventsDAO{privateclientconstructor(){this.client=generateClient()}asynccreateEvent(createInput: CreateEventInput): Promise<Event>{returnthis.client.graphql({query: createEvent,variables: {input: createInput,},}).then(({ data })=>data.createEvent)}asyncgetEventById(id: string): Promise<Event>{returnthis.client.graphql({query: getEvent,variables: {
id,},}).then(({ data })=>{if(!data.getEvent){throwcreateError({status: 404,message: 'Event not found'})}returndata.getEvent})}asyncupdateEvent(updateInput: UpdateEventInput): Promise<Event>{awaitthis.getEventById(updateInput.id)// Check if event exists// TODO: Implement optimistic lockingreturnthis.client.graphql({query: updateEvent,variables: {input: updateInput,},}).then(({ data })=>data.updateEvent)}asyncdeleteEvent(deleteInput: DeleteEventInput): Promise<void>{awaitthis.client.graphql({query: deleteEvent,variables: {input: deleteInput,},}).then(({ data })=>{if(!data.deleteEvent){throwcreateError({status: 404,message: 'Event not found'})}})}asyncqueryEventsByType(type: EventType,nextToken?: string|null): Promise<EventPage>{constresults=awaitthis.client.graphql({query: listEvents,variables: {filter: {type: {eq: type,},},
nextToken,},})return{items: results.data.listEvents.items,nextToken: results.data.listEvents.nextToken,}}}exportdefaultEventsDAO
Log output
// Put your logs below this line
ERROR { data: null,
errors:
[ { path: null,
locations: [Array],
message: "Variable 'involvedOrgs' has an invalid value." } ] }
asynccreateEvent(createInput: CreateEventInput): Promise<Event>{returnthis.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.
.graphqlconfig.yml
{ data: null, errors: [ { path: null, locations: [Array], message: "Variable 'involvedPeople' has an invalid value." } ] }
dao.ts
Expected 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
The text was updated successfully, but these errors were encountered: