I am building a nativescript mobile application which consume graphql API, and I am using apollo client via apollo boost.
The problem appear when I am trying to send array of objects inside the mutation like below:
let {
to,
total,
drugList
} = order
apolloClient.mutate({
mutation: gql `mutation {
makeOrder(
to: "${to}",
total: ${total},
drugList: ${drugList}
){
id
}
}`
}).then((res) => {
console.log(res)
}).catch((error) => {
console.log(error)
})
I have tried to log the drugList inside a template literals like:
console.log(`${drugList}`)
But I got [object object],[object object] then I have tried to use ${[...drugList]} instead and I got the desired structure of array of objects but the mutate function of apollo client doesn't accept it (doesn't execute the mutation or log an error).
Am I miss something to make it run or are there any recommendation to run it?
order, what value exactly doesdrugListhave?gql-tagged template literal, which you cannot compare to the simple template string in yourconsole.logtest.console.log(gql `mutation { makeOrder( to: "${to}", total: ${total}, drugList: ${drugList} ){ id } }`)