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

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

问题描述

出于好奇,我开始阅读有关GraphQL的文章.基于

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指向实体图的不同子集的表示形式,并且有一个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天全站免登陆