我正在尝试向使用阿波罗的GraphQL服务器发送突变查询。
然而,我只看到实现这一点的唯一方法是使用突变组件。https://www.apollographql.com/docs/react/essentials/mutations/#the-mutation-component
有没有一种简单的方法可以发送突变来做这样的事情?
从‘graphql-tag’导入gql;
client.query({
query: gql`
query TodoApp {
todos {
id
text
completed
}
}
`,
})
.then(data => console.log(data))
.catch(error => console.error(error));发布于 2019-07-15 15:01:00
您不需要突变组件来触发突变。
您可以只在gql查询对象中传递突变,如下所示:
client.query({
query: gql`
mutation MyMutation {
doSomthing {
id
returnedValue1
}
}
`,
})
.then(data => console.log(data))
.catch(error => console.error(error));希望能有所帮助。
https://stackoverflow.com/questions/57031867
复制相似问题