GraphQL 是无状态的吗? [英] Is GraphQL stateless?

查看:23
本文介绍了GraphQL 是无状态的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于好奇,我开始阅读 GraphQL.基于 这篇文章,对我来说看起来像是 REST API 请求.是无国籍的吗?意味着它没有请求,没有来自服务器的响应?如果是,那么为什么它比 REST API 资源更轻?

Out of curiosity I start to read about GraphQL. Based on the samples on this article, it looks like REST API request to me. Is it stateless? means it has no request, no response from the server? If yes, then how come it is more resource lighter than REST API?

推荐答案

它是无状态的吗?

Is it stateless?

是的,只要服务器不需要任何客户端状态知识即可正确解释请求;所有必要的信息都包含在请求本身(标头和正文)中.

Yes, in so far as the server doesn't require any knowledge of client state to correctly interpret the request; all of the necessary information is included in the request itself (headers and body).

对我来说看起来像是 REST API 请求.

It looks like REST API request to me.

它可能没有.它在超媒体约束上完全失败(规范没有任何对链接的引用,这是一个很大的提示).它在资源"上有点混乱.

It probably doesn't. It fails utterly on the hypermedia constraint (the specification lacks any reference to links, which is a big hint). It's a bit muddled on "resources".

来自 graphql.org

HTTP 通常与 REST 相关联,它使用资源"作为其核心概念.相比之下,GraphQL 的概念模型是一个实体图.因此,GraphQL 中的实体不是由 URL 标识的.

HTTP is commonly associated with REST, which uses "resources" as its core concept. In contrast, GraphQL's conceptual model is an entity graph. As a result, entities in GraphQL are not identified by URLs.

因此,您将获得许多不同的 URI,它们指向实体图的不同子集的表示,以及用于图的所有修改的单个 URI.在统一接口的背后,这些资源"都将通过一条路由实现.

So you get a number of different URI that point to representations of different subsets of the entity graph, and a single URI used for all modifications of the graph. Behind the uniform interface, these "resources" will all be implemented using a single route.

REST 是一种架构风格,选择因为它们在候选架构上产生的特性."看起来 GraphQL 对一组不同的属性感兴趣;也就是说,他们正在尝试解决不同类型的问题.

REST is an architectural style, "chosen for the properties they induce on candidate architectures." It looks as though GraphQL is interested in a different set of properties; which is to say they are trying to solve a different kind of problem.

这篇关于GraphQL 是无状态的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆