GraphQL在哪个层次?

huangapple go评论58阅读模式
英文:

In what layer is GraphQL?

问题

GraphQL并不直接映射到OSI模型的特定层。它通常运行在HTTP之上,因此可以视为在应用层(Layer 7)上实现,但请注意,OSI模型只有七层,没有"Layer 8"。

英文:

I've been learning about client server communication and read that according to OSI there are several layers where protocols are implemented. For example, TCP happens at layer 4 and HTTP at layer 7.

In what layer is GraphQL implemented?

I've been using it "over" HTTP so it seems it should be in layer 8 but it doesn't exist in OSI.

答案1

得分: 4

尽管仍然经常被用作分析协议的基础,OSI模型的初衷是作为设计协议堆栈的框架。它是在20世纪80年代设计的,早在互联网成为主导网络系统之前,也早在蒂姆·伯纳斯-李等人在1990年代中期发明HTTP之前。它与当前协议的相关性和适用性存在疑问。

实际上,常用的协议堆栈是TCP/IP,它并不是基于那些定义而设计的,并且与它们并不完全对应。在TCP/IP中,有一个单独的“应用层”,它大致对应于“OSI应用层、表示层和大部分会话层”(维基百科摘要)。HTTP通常被简称为“第7层”,仅仅是因为它是最接近的匹配,但它并不明确依赖于OSI模型所设想的第5和第6层协议的存在。

这两个定义都没有捕捉到一个现代的事实,即许多协议并非直接建立在TCP/IP之上,而是建立在HTTP之上。正如你所说,在标准的OSI模型中并不存在“第8层”。使用HTTP更多是出于实际代码重用的需要,而非理论上的责任划分。

类似的问题也适用于传统的TLS:它位于TCP(传输层)和HTTP(应用层)之间的某个地方,但与原始的OSI模型中第5或第6层的定义并不对应。在现代用法中,它还协商了应用层所需的方面(例如服务器名称指示)。

情况进一步复杂化了HTTP/3,它完全绕过了TCP,构建了一个基于UDP和名为QUIC的新协议的新堆栈。QUIC整合了以前属于TCP、TLS和HTTP的特性,例如合并握手,而不是分别建立TCP、TLS和HTTP/2会话。

在HTTP/3上运行GraphQL会得到IP -> UDP -> QUIC -> HTTP/3 -> GraphQL,这是一组具有完全不同职责的层,与40年前OSI模型所设想的完全不同。

英文:

Although still frequently used as a basis for analysing protocols, the OSI model was intended as a framework for designing protocol stacks. It was designed in the 1980s, before the Internet became the dominant networking system, and long before the invention of HTTP by Tim Berners-Lee et al in the mid-1990s. Its relevance and applicability to current protocols is questionable.

The actual protocol stack in common use is TCP/IP, which was not designed based on those definitions, and doesn't map cleanly to them. In TCP/IP, there is a single "application layer", which corresponds roughly to "the OSI application layer, presentation layer, and most of the session layer" (Wikipedia summary). HTTP is commonly called "layer 7" simply because that's the closest match, but it doesn't explicitly rely on the existence of any layer 5 and 6 protocols, as was envisioned by the OSI model.

Neither definition captures the modern reality that many protocols are layered not directly onto TCP/IP, but onto HTTP. As you say, there is no "layer 8" in the standard OSI model. The use of HTTP is more a matter of pragmatic code reuse than theoretical division of responsibilities.

A similar problem applies to traditional TLS: it sits somewhere in between TCP (transport layer) and HTTP (application layer), but doesn't correspond to the definitions for layer 5 or 6 in the original OSI model. In modern usage, it also negotiates aspects needed by the application layer (e.g. Server Name Indication).

The picture is further muddied by HTTP/3, which bypasses TCP completely, building a new stack on top of UDP and a new protocol called QUIC. QUIC incorporates features that were previously part of TCP, TLS, and HTTP, such as a combined handshake, rather than separately establishing TCP, TLS, and HTTP/2 sessions.

Running GraphQL over HTTP/3 gives you IP -> UDP -> QUIC -> HTTP/3 -> GraphQL, a set of layers with completely different responsibilities to those envisioned by the OSI 40 years ago.

huangapple
  • 本文由 发表于 2023年6月13日 19:02:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/76464234.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定