Apollo 中查询和变异之间的区别?

difference between Query and Mutation in Apollo?

我们可以使用 Query 和 Mutation 向服务器发出一些请求。在这些查询中,我们可以传递一些参数,并且在这两种情况下我们都会从服务器获得一些结果。唯一的区别是我们可以从我们的 props 中调用突变,比如 "this.props.mutation",但它看起来像一个语法糖,因为我们可以将 HOC 包装在 "withApollo" 中,我们将收到 "query" 道具中的方法。那么这两种请求的主要区别是什么?

严格来说没有区别

... technically any query could be implemented to cause a data write. However, it's useful to establish a convention that any operations that cause writes should be sent explicitly via a mutation.

但是,参考实现确实强制执行以下内容。

While query fields are executed in parallel, mutation fields run in series, one after the other.

This means that if we send two incrementCredits mutations in one request, the first is guaranteed to finish before the second begins, ensuring that we don't end up with a race condition with ourselves.

这两句引述都可以从下面的链接中找到。

http://graphql.org/learn/queries/#mutations

http://graphql.org/learn/queries/#multiple-fields-in-mutations