Pagination & Refetching

Fetching new data for an OperationRequest in Ferry is easy. Just add a request of the same type and with the same requestId to the Client.requestController.


If no requestId is provided, Ferry will automatically assign a uuid when the request is instantiated.

If you're using Flutter, make sure to either instantiate the request outside of the build() method or explicitly provide a requestId. Otherwise, a new request will be instantiated on every build with a new ID.

final reviewsReq = GReviewsReq();
/// 60db32c0-e9d7-11ea-9678-054319a5b10b


For example, if we are listening to the following request:

final reviewsReq = GReviewsReq(
(b) => b
..vars.first = 3
..vars.offset = 0,
client.request(reviewsReq).listen((response) => print(response));

We can refetch the query by adding the request to the requestController:


Once the response is received, any request() Streams that were listening to reviewsReq will get updated with the new data.


Rather than just replacing the previous result with the refetched result, we may want to combine the results to enable pagination.

To do this, we need to create a copy of our original request that will fetch the next set of results and include an updateResult calback that tells ferry how to combine the results.

For example, let's fetch the next 3 reviews.

final nextReviewsReq = reviewsReq.rebuild(
(b) => b
..vars.offset = 3
..updateResult = (previous, result) =>
previous?.rebuild((b) => ??

The next event received by our request() Stream will now include all six reviews.