我可以使用 GraphQL/Relay 查询在不获取的情况下修改数据吗

Can I use a GraphQL/Relay query for modifying data without fetch

中继突变定义为"operations that consist of writes to the data store followed by a fetch of any changed fields."。诸如日志记录之类的东西呢?我还没有找到突变与查询的正式定义,就像在 REST POST vs GET vs PUT 协议中找到的那样。我是否正确认为当希望修改和返回数据时会使用突变,但如果我只需要更新某些内容,那么标准查询就可以了?在某些情况下,我可能会获取数据但更新不需要返回的内容。

A Relay mutation is defined as an "operations that consist of writes to the data store followed by a fetch of any changed fields.". What about something such as logging?

如果我正确理解了您对 logging 的困惑,您可能想在服务器中记录一些内容,但您的客户端没有任何要更新的内容。如果您想使用 GraphQL 和 Relay 进行日志记录,您应该将此日志记录操作建模为突变。查询实际上是一个只读操作。

如果 logging 是一个打字错误,而你实际上是指 login,那么之前有很多关于 Relay 和 GraphQL 领域中身份验证的答案.检查以下 SO 和博客文章:

  1. Relayjs Graphql user authentication
  2. javascript - Authentication and privileges on Relay/GraphQL
  3. A guide to authentication in GraphQL — Building Apollo — Medium
  4. Auth in GraphQL — Part 2 — Building Apollo — Medium

I have not found a formal definition of mutations vs query as one would find in the REST POST vs GET vs PUT protocols.

来自 GraphQL draft specification:

There are two types of operations that GraphQL models:

* query – a read‐only fetch.
* mutation – a write followed by a fetch.

Am I correct that one would use a mutation when there is a desire to have data be modified and returned but if I just need to update something then a standard query is fine?

不,那是不正确的。变异是您应该用于对数据进行任何类型修改的操作。如果您不需要在更新后获取任何数据,则只需不在 fat query 中包含任何内容。截至目前,GraphQL 没有任何特定的更新操作类型,之后不获取数据。