简体   繁体   English

graphQL多重突变事务

[英]graphQL multiple mutations transaction

Apparently graphQL mutations are executed one by one sequentially. 显然,graphQL突变是按顺序逐个执行的。

Source : 资源 :

In GraphQL, mutations are executed as a sequence. 在GraphQL中,突变作为序列执行。 Otherwise, it's hard to detect errors like adding the same author again and again. 否则,很难检测到一次又一次地添加同一作者的错误。

It's totally up to the GraphQL server implementation to implement mutations like this. 完全由GraphQL服务器实现来实现这样的突变。 Reference NodeJS implementation and other community implementations for Python and Scala follow this. 参考NodeJS实现和Python和Scala的其他社区实现遵循这一点。

If I understand it right, this does this prevent : 如果我理解正确,这可以防止:

  • executing the requests in parallel 并行执行请求
  • the use of transactions over multiple requests 在多个请求中使用事务

What is the rationale behind this design decision ? 这个设计决定背后的理由是什么? Are there other projects that do it differently ? 还有其他项目以不同的方式进行吗?

Actually, GraphQL highly encourages request concurrency. 实际上,GraphQL强烈鼓励请求并发。 Requests can be handled in parallel. 请求可以并行处理。 Each request performs the individual mutations of that request in serial, but multiple requests can be processed concurrently. 每个请求都会串行执行该请求的各个突变,但可以同时处理多个请求。

It's important to denote the difference between mutations and requests, especially regarding concurrency. 表示突变和请求之间的区别很重要,特别是在并发方面。

It's also important to denote that GraphQL tells you nothing about how the edits are applied outside of a single request. 同样重要的是,表示GraphQL不会告诉您如何在单个请求之外应用编辑。 It's your code abstraction, you decide whether to use SQL begin...commit to block database writes or just make the update calls directly and roll the dice. 这是你的代码抽象,你决定是否使用SQL开始...提交阻止数据库写入或直接进行更新调用并滚动骰子。

Serial edit processing on a transaction is a very common practice in database design, and a set of commands for this can be seen in most database languages. 对事务进行串行编辑处理是数据库设计中非常常见的做法,在大多数数据库语言中都可以看到一组用于此目的的命令。

In SQL, mutations are often bracketed by BEGIN and COMMIT. 在SQL中,突变通常被BEGIN和COMMIT括起来。 In Redis a MULTI EXEC block offers this functionality. 在Redis中,MULTI EXEC块提供此功能。

This is primarily what I've seen. 这主要是我见过的。 However, unordered, parallel edit processing certainly is possible as long as you make sure the results are path independent and you can find a way to guarantee all ACID properties hold. 但是,只要您确保结果与路径无关,并且您可以找到保证所有ACID属性保持的方法,就可以进行无序的并行编辑处理。

There are ways to do this in many languages, but I can only think of an example implementation of this in Redis off the top of my head. 有很多方法可以用多种语言来实现这一点,但我只能想到Redis中的一个示例实现。

You could map the edits to a set of short Lua scripts that check the value of the transaction key for their serialized selves, and if they found a match, they'd return before applying. 您可以将编辑映射到一组简短的Lua脚本,这些脚本检查其序列化自我的事务键值,如果找到匹配,则在应用之前返回。 Otherwise, they'd apply the edit, and append the serialized edit to the transaction body. 否则,他们将应用编辑,并将序列化编辑附加到事务正文。

NOTE: If you have dependent edits (Create table, push entry to table), you can really shoot yourself in the foot avoiding serial edit execution. 注意:如果您有依赖编辑(创建表格,将表格推入表格),您可以真正拍摄自己的脚,避免连续编辑执行。

As far as transactions over multiple requests? 至于多个请求的交易? I've never really used them and this thread is more suited for that question. 我从来没有真正使用它们,这个线程更适合这个问题。

Multi-step database transaction split across multiple HTTP requests 跨多个HTTP请求拆分多步骤数据库事务

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Сombine 突变在草莓 Graphql - Сombine mutations in one in Strawberry Graphql 在 django-graphql-jwt 中使用 @login_required 进行查询/突变会导致 graphql.error.located_error.GraphQLLocatedError - Using @login_required for queries/mutations in django-graphql-jwt leads to graphql.error.located_error.GraphQLLocatedError 使用 GraphQL 和石墨烯进行多级过滤 - Filter at multiple levels with GraphQL and Graphene GCP 数据存储区 Python - InvalidArgument:400 非事务性提交可能不包含影响同一实体的多个突变 - GCP Datastore Python - InvalidArgument: 400 A non-transactional commit may not contain multiple mutations affecting the same entity 一笔交易中的多次转账? - Multiple transfers within one transaction? MySQLdb每个连接有多个事务 - MySQLdb with multiple transaction per connection Django 中一个请求中的 GraphQL 多个查询 - GraphQL multiple queries in one request in Django GraphQL - 多个必填输入字段的“非此即彼” - GraphQL - 'either / or' for multiple required input fields 如何创建接受多个 ID graphql 的过滤器? - How to create filter that takes in multiple ids graphql? Django:在事务中保存多个ManyToMany字段 - Django: Saving multiple ManyToMany fields within a transaction
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM