Ferry is built using a modular system of TypedLinks. A TypedLink is a class that implements a request() method, which returns a Stream<OperationResponse>.
There are two main types of behavior for a TypedLink:
- Terminating Links: These resolve the request directly (e.g., fetching from a Cache or a Network link) and do not call a
forward callback. - Forwarding Links: These modify the request or response and then call the
forward() callback to pass the request to the next link in the chain.
By composing these links, you can build complex request/response pipelines.
/// A terminating link that fetches the operation from the Cache, mapping the
/// result to an [OperationResponse].
class CacheTypedLink extends TypedLink {
final Cache cache;
CacheTypedLink(Cache cache) : cache = cache ?? Cache();
@override
Stream<OperationResponse<TData, TVars>> request<TData, TVars>(
OperationRequest<TData, TVars> operationRequest, [
forward,
]) => ...
}