Skip to content

Fluent Queries

Arun Prakash edited this page Sep 21, 2025 · 1 revision

Fluent Queries

A lightweight fluent layer sits atop the existing request classes to help you compose requests without manually instantiating them. This does not change the public interface types; it exposes convenient builders via client.<interface>.query.

Key ideas

  • Each interface (e.g., client.posts) exposes a query getter that auto-seeds the appropriate list request (e.g., ListPostRequest).
  • You can chain helpers like withPage, withPerPage, withSearch, withOrder, withOrderBy, etc.
  • For params not covered by helpers, mutate the underlying seed via configureSeed((seed) { ... }) or access builder.seedRequest directly.
  • This layer is non-breaking; the base CRUD mixins remain unchanged.

Examples

Basic list

final res = await client.posts.query
  .withPage(1)
  .withPerPage(20)
  .withSearch('welcome')
  .withOrder(Order.desc)
  .execute();

Advanced: seed mutation

final res2 = await client.posts.query
  .configureSeed((seed) {
    seed.context = RequestContext.view;
  })
  .execute();

Access the seed directly

final builder = client.posts.query;
builder.seedRequest.context = RequestContext.view;
final res3 = await builder.execute();

Common helpers

  • withPage(int) / withPerPage(int)
  • withSearch(String)
  • withOrder(Order) / withOrderBy(String)
  • withContext(RequestContext)
  • withInclude(List<int>) / withExclude(List<int>)
  • withCategories(List<int>) / withTags(List<int>)
  • withAfter(DateTime) / withBefore(DateTime)
  • withAuthor(List<int>) / withAuthorExclude(List<int>)
  • withOffset(int) / withSlug(List<String>) / withStatus(List<ContentStatus>)

Note: Some auto-seeded builders (e.g., revisions/navigation) default to placeholder IDs. Set them via configureSeed (or seedRequest) before execute().

Clone this wiki locally