dartpollo
A Dart GraphQL client with built-in caching support. Executes typed GraphQL queries generated by dartpollo_generator.
Features
- Typed GraphQL execution — Execute generated query classes and get typed responses
- Caching — Built-in cache layer with pluggable stores (in-memory, Hive)
- Cache policies — Control caching behavior per-query (cache-first, network-only, etc.)
- GQL link support — Built on top of the
gql_linkecosystem
Installation
dependencies:
dartpollo: ^0.1.0
dev_dependencies:
build_runner: ^2.10.0
dartpollo_generator: ^0.1.0
Usage
import 'package:dartpollo/dartpollo.dart';
// Basic client
final client = DartpolloClient(link: yourHttpLink);
final response = await client.execute(MyQuery());
print(response.data);
// Cached client
final cachedClient = DartpolloCachedClient(
link: yourHttpLink,
cacheStore: InMemoryCacheStore(),
);
final response = await cachedClient.execute(
MyQuery(),
cachePolicy: CachePolicy.cacheFirst,
);
API
Clients
DartpolloClient— Standard GraphQL clientDartpolloCachedClient— Client with caching support
Cache
CacheStore— Abstract cache store interfaceInMemoryCacheStore— In-memory cache implementationHiveCacheStore— Persistent cache using HiveCachePolicy— Cache behavior policiesCacheEntry— Individual cache entriesCacheContext— Cache context for requests
Migration Guide
If you were using the old monolithic dartpollo package (before the monorepo split), follow these steps to migrate:
1. Update pubspec.yaml
The code generator has been extracted into a separate package. Add dartpollo_generator as a dev dependency:
Before:
dependencies:
dartpollo:
# your version/path
dev_dependencies:
build_runner: ^2.10.0
After:
dependencies:
dartpollo: ^0.1.0
dev_dependencies:
build_runner: ^2.10.0
dartpollo_generator: ^0.1.0 # ← NEW: generator is now a separate package
Note:
dartpollo_annotationis automatically included as a transitive dependency — you don't need to add it manually.
2. Update build.yaml
Two changes are needed:
- Builder key changed from
dartpollo:todartpollo_generator|dartpollo:(fully qualifiedpackage|builder_nameformat) outputoption removed — output paths are now auto-generated under__generated__/directories. Remove anyoutput:entries from yourschema_mapping.
Before:
targets:
$default:
sources:
- $package$
- lib/**
- schema.graphql
builders:
dartpollo:
options:
schema_mapping:
- schema: schema.graphql
queries_glob: lib/**/*.graphql
output: lib/__generated__
After:
targets:
$default:
sources:
- $package$
- lib/**
- schema.graphql
builders:
dartpollo_generator|dartpollo: # ← updated builder key
options:
schema_mapping:
- schema: schema.graphql
queries_glob: lib/**/*.graphql
# output is no longer needed — auto-generated under __generated__/
For the full list of configuration options, see the dartpollo_generator README.
3. Regenerate code
dart run build_runner clean
dart run build_runner build --delete-conflicting-outputs
4. No import changes needed
All existing imports (package:dartpollo/dartpollo.dart) continue to work. The client barrel file re-exports all types from dartpollo_annotation, so generated code and your application code remain compatible without any import changes.
Related Packages
- dartpollo_generator — Code generator for GraphQL schemas
- dartpollo_annotation — Shared types (transitive dependency)