gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 01:44:14 28 4
gpt4 key购买 nike

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

最佳答案

严格来说没有区别。

... 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

关于apollo - Apollo 中查询和变异之间的区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47789492/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com