不使用 Mutation 组件触发 GraphQL 突变
Trigger a GraphQL mutation not using the Mutation component
我正在尝试向使用 Apollo 的 GraphQL 服务器发送变更查询。
但是,我只看到实现此目的的唯一方法是使用 Mutation 组件。
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));
您不需要突变组件来触发突变。
您可以只在 gql
查询对象中传递突变,例如:
client.query({
query: gql`
mutation MyMutation {
doSomthing {
id
returnedValue1
}
}
`,
})
.then(data => console.log(data))
.catch(error => console.error(error));
我正在尝试向使用 Apollo 的 GraphQL 服务器发送变更查询。
但是,我只看到实现此目的的唯一方法是使用 Mutation 组件。 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));
您不需要突变组件来触发突变。
您可以只在 gql
查询对象中传递突变,例如:
client.query({
query: gql`
mutation MyMutation {
doSomthing {
id
returnedValue1
}
}
`,
})
.then(data => console.log(data))
.catch(error => console.error(error));