变异操作的 GraphQL 顺序

标签 graphql graphql-mutation

我正在创建一个有效的突变,但我不确定它是否按照我认为的方式工作。但是,我想知道执行顺序是什么?

  • 异步
  • 从上到下同步
  • 同步随机顺序
  • 其他

我想确保在执行插入/更新插入之前从表中删除某些项目。使用以下突变查询字符串,这是否始终会执行我想要的操作,或者它是否会时不时地工作,因为我假设它是同步的,但实际上它是异步的?

mutation MyMutation(...) {
  update_my_table_1(...) { }

  delete_my_table_2(...) { }

  insert_my_table_2(...) { }
}

最佳答案

来自spec :

If the operation is a mutation, the result of the operation is the result of executing the mutation’s top level selection set on the mutation root object type. This selection set should be executed serially.

It is expected that the top level fields in a mutation operation perform side‐effects on the underlying data system. Serial execution of the provided mutations ensures against race conditions during these side‐effects.

根突变类型的字段总是按顺序解析。任何其他 类型(如查询根类型或任何“嵌套”类型)的订单字段都是 left up to the implementation ,尽管在大多数(如果不是全部)实现中,这意味着字段是并行解析的。

所以在上面的例子中,insert_my_table_2要到delete_my_table_2才会执行,delete_my_table_2要到才会执行update_my_table_1 是。

关于变异操作的 GraphQL 顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62432519/

相关文章:

javascript - 使用 apollo 改变数组

graphql - 使用 Graphql 和 Amplify/AppSync 根据先前值进行突变

python - 如何使用 graphene-django 定义突变的自定义输出类型?

database - 当 Relay 游标分页总是获取整个数据集时,它如何处理大数据集?

graphql - 以优雅的方式将 GraphQL 变量传递给第二个函数

node.js - GraphQL 嵌套解析器

shopify storefront api 如何在单个集合中列出产品

node.js - GraphQL 嵌套查询查找