Incremental Delivery🔗
Note that incremental delivery is currently experimental and may change in the future. The
@deferand@streamdirectives are not part of the GraphQL specification yet. They are an RFC in the GraphQL Working Group and the transport RFC they are delivered over is a draft as well.graphql-corealso still exposes incremental execution under an "experimental" name, and has not released a stable version with support for it.
Undine has experimental support for incremental delivery of data
using the @defer and @stream directives. To enable incremental delivery,
all of the following must be true:
graphql-core{:target="blank"} version must be3.3.0rc0_exactly (later versions may work, but are not tested)EXPERIMENTAL_INCREMENTAL_DELIVERYmust be set toTrue- Async support must be enabled
Let's look at an example of incremental delivery using the @defer and @stream directives.
Given the following schema:
If we wanted to query the "slow" field, the client would need to wait for five seconds for the server to resolve it before it can show any of the other data.
However, using the @defer directive, the client can receive the rest of the data immediately and
the deferred data when its complete. The @defer directive works on fragment spreads an inline fragments.
Similarly, if we wanted to query the "countdown" field, the client would need to wait for ten seconds for the entire countdown to end before it can show any of the other data.
However, using the @stream directive, the client can receive the rest of the data immediately
and stream in each countdown result as they become available. The @stream directive works on list fields.