惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The Cloudflare Blog
Microsoft Security Blog
Microsoft Security Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
L
LangChain Blog
W
WeLiveSecurity
P
Proofpoint News Feed
月光博客
月光博客
NISL@THU
NISL@THU
L
LINUX DO - 最新话题
Webroot Blog
Webroot Blog
T
Threatpost
Y
Y Combinator Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
T
Threat Research - Cisco Blogs
Vercel News
Vercel News
Jina AI
Jina AI
阮一峰的网络日志
阮一峰的网络日志
S
Schneier on Security
J
Java Code Geeks
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
小众软件
小众软件
MyScale Blog
MyScale Blog
N
News and Events Feed by Topic
Stack Overflow Blog
Stack Overflow Blog
有赞技术团队
有赞技术团队
The Hacker News
The Hacker News
Schneier on Security
Schneier on Security
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Help Net Security
Help Net Security
Recent Announcements
Recent Announcements
S
Security @ Cisco Blogs
C
CXSECURITY Database RSS Feed - CXSecurity.com
S
Securelist
T
The Exploit Database - CXSecurity.com
云风的 BLOG
云风的 BLOG
C
Cisco Blogs
雷峰网
雷峰网
量子位
Google DeepMind News
Google DeepMind News
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Spread Privacy
Spread Privacy
L
Lohrmann on Cybersecurity
I
Intezer
T
The Blog of Author Tim Ferriss
G
GRAHAM CLULEY
D
DataBreaches.Net
V
Vulnerabilities – Threatpost
P
Privacy & Cybersecurity Law Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
罗磊的独立博客

Blog | GraphQL

GraphQL Foundation Monthly Newsletter April 2021 GraphQL Foundation Monthly Newsletter March 2021 GraphQL Foundation Monthly Newsletter February 2021 GraphQL Foundation Monthly Newsletter October 2020 GraphQL Foundation Monthly Newsletter September 2020 Google Season of Docs 2020 Participant: Carolyn Stransky GraphQL Foundation Monthly Newsletter August 2020 Google Summer of Code 2020 Participant: Naman GraphQL joins Google Season of Docs Web-based GraphQL IDEs for the win: How & Why Playground & GraphiQL are joining forces Announcing the 1st GraphQL Foundation Annual Report Linux Foundation Training Announces a Free Online Course-Exploring GraphQL: A Query Language for APIs GraphQL Foundation Launches Interactive Landscape and Welcomes New Members from Open Source Summit Europe The GraphQL Foundation Announces Collaboration with the Joint Development Foundation to Drive Open Source and Open Standards Channel Futures: GraphQL API Query Language Growing, Gets Own Support Foundation Datanami: Will GraphQL Become a Standard for the New Data Economy? SD Times: The Linux Foundation announces plans to form GraphQL foundation The Register: Facebook’s open-source license drama-zone GraphQL gets swanky digs in Linux mansion eWeek: GraphQL API Specification Moving Forward with Independent Foundation InfoWorld: GraphQL gets its own foundation The Linux Foundation Announces Intent to Form New Foundation to Support GraphQL ProgrammableWeb: GraphQL Moving to Neutral, Open-Source Foundation Leaving technical preview | GraphQL Wrapping a REST API in GraphQL Mocking your server is easy with GraphQL Subscriptions in GraphQL and Relay GraphQL: A data query language
Improving Latency with @defer and @stream Directives
Rob Richard, · 2020-12-08 · via Blog | GraphQL

Rob Richard and Liliana Matos are front-end engineers at 1stDibs.com. They have been working with the GraphQL Working Group as champions of the the @defer and @stream directives.

The @defer and @stream directives have been a much anticipated set of features ever since Lee Byron first talked about it at GraphQL Europe 2016. For most of 2020, we have been working with the GraphQL Working Group to standardize this feature. It is now a Stage 2 proposal, but to advance further, we are looking to the GraphQL community to try using these directives and provide feedback. We have released experimental versions of GraphQL.js and express-graphql. They are published to npm under graphql@experimental-stream-defer and express-graphql@experimental-stream-defer. We encourage everyone interested in this feature to try out these releases and let us know how it goes in the issue created for feedback. Read on to find out more about what this proposal offers.

One of the disadvantages of GraphQL’s request/response model is that the GraphQL response is not returned to clients until the entire request has finished processing. However, not all requested data may be of equal importance, and in some use cases it may be possible for applications to act on a subset of the requested data. An application can speed up its time-to-interactive if the GraphQL server can send the most important data as soon as it’s ready. The new @defer and @stream directives allow GraphQL servers to do exactly that by returning multiple payloads from a single GraphQL response.

The @defer directive can be applied to fragment spreads and inline fragments. It is a declarative way for developers to mark parts of a query as non-essential for immediate return.

Here’s an example of the @defer directive:

Request#

query {

person(id: "cGVvcGxlOjE=") {

name

...HomeworldFragment @defer(label: "homeworldDefer")

}

fragment HomeworldFragment on Person {

homeworld {

name

}

}

Response#

Payload 1

{

"data": {

"person": {

"name": "Luke Skywalker"

}

},

"hasNext": true

}

Payload 2

{

"label": "homeworldDefer",

"path": ["person"],

"data": {

"homeworld": {

"name": "Tatooine"

}

},

"hasNext": false

}

When the GraphQL execution engine encounters the @defer directive, it will fork execution and begin to resolve those fields asynchronously. While the deferred payload is still being prepared, the client can receive and act on the initial payload. This is most useful when the deferred data is large, expensive to load, or not on the critical path for interactivity.

Similar to @defer, the @stream directive also allows the client to receive data before the entire result is ready. @stream can be used on list fields. Here’s an example of the @stream directive:

Request#

query {

person(id: "cGVvcGxlOjE=") {

name

films @stream(initialCount: 2, label: "filmsStream") {

title

}

}

Response#

Payload 1

{

"data": {

"person": {

"name": "Luke Skywalker",

"films": [

{ "title": "A New Hope" },

{ "title": "The Empire Strikes Back" }

]

}

},

"hasNext": true

}

Payload 2

{

"label": "filmsStream",

"path": ["person", "films", 2],

"data": {

"title": "Return of the Jedi"

},

"hasNext": true

}

Payload 3

{

"label": "filmsStream",

"path": ["person", "films", 3],

"data": {

"title": "Revenge of the Sith"

},

"hasNext": false

}

When the GraphQL execution engine encounters the @stream directive, it will resolve as many list items specified by the initialCount argument. The rest will be resolved asynchronously. This is especially useful for an interface where only a few elements can be rendered above the fold. The client can render these elements as soon as possible while the server is still resolving the rest of the data.

While the GraphQL specification doesn’t specify transport protocols, we expect the most common transport for queries with @defer/@stream to be HTTP with chunked transfer encoding. This allows a GraphQL server to keep a standard HTTP connection open, while streaming each payload to the client as soon as it’s ready. It has low overhead, has been supported by browsers for decades, and can work easily with most infrastructure.

You can learn more about these directives at:

Rob Richard, Liliana Matos, Front-End Engineering, 1stDibs.com