Javascript 如何向apollo客户端请求添加对象数组?

Javascript 如何向apollo客户端请求添加对象数组?,javascript,graphql,apollo-client,Javascript,Graphql,Apollo Client,我正在构建一个使用GraphQLAPI的nativescript移动应用程序,并通过apollo boost使用apollo客户端 当我试图发送变异中的对象数组时,出现如下问题: let { to, total, drugList } = order apolloClient.mutate({ mutation: gql `mutation { makeOrder( to: "${to}", tot

我正在构建一个使用GraphQLAPI的nativescript移动应用程序,并通过apollo boost使用apollo客户端

当我试图发送变异中的对象数组时,出现如下问题:

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)
})
我已尝试在模板文本中记录药物列表,如:

console.log(`${drugList}`)
但是我得到了[object object],[object object]然后我尝试使用
${[…drugList]}
,我得到了所需的对象数组结构,但是apollo客户端的mutate函数不接受它(不执行变异或记录错误)


我是否错过了让它运行的东西,或者是否有任何运行它的建议?

感谢Bergi在他注意到我使用gql标记的模板文本的查询后,我无法与console.log测试中的简单模板字符串相比

所以我搜索了一下,发现变量属性可以解决这个问题,所以这里是最终结果

let {
    to,
    total,
    drugList
} = order

apolloClient.mutate({
    mutation: gql `mutation ($to: ID!, $total: Float!, $drugList: [OrderDrugsListInput!]!) {
        makeOrder(
            to: $to,
            total: $total,
            drugList: $drugList
        ){
            id
        }
    }`,
    variables: {
        to: to,
        total: total,
        drugList: drugList
    }
}).then((res) => {
    console.log(res)
}).catch((error) => {
    console.log(error)
})

什么是
order
drugList
到底有什么值?请注意,在您的查询中,您使用的是
gql
标记的模板文本,您无法与
控制台中的简单模板字符串进行比较。log
测试。@Bergi order对象包含to、total和drugList,它们是id,float和array分别是对象。@Bergi好的,这是一个很好的说明,但是如何在其中发送对象数组呢?您还可以尝试
console.log(gql`mutation{makeOrder(to:${to}),total:${total},drugList:${drugList}{id}`