A Flutter DevTools extension for inspecting GraphQL cache
This package adds a new tool to Flutter's DevTools, utilizing the devtools_extensions framework. With this tool, you can:
- View a list of data stored in the GraphQL cache store
- The data list is categorized into three tabs: Cache, Query, and Mutation
- Inspect the details of each cache entry
Currently, gql_cache_lens
supports the following GraphQL packages:
To install gql_cache_lens
, add the package to your pubspec.yaml
file:
dev_dependencies:
gql_cache_lens: ^0.9.0
Alternatively, you can run the following command
flutter pub add --dev gql_cache_lens
To use gql_cache_lens
, add a ServiceExtensionHandler
as shown below.
Return a JSON-encoded Map obtained from the Store
in the ServiceExtensionResponse
's result.
final GrpahQLClient client = ...;
registerExtension('ext.gql_cache_lens.load', (_, __) async {
final GraphQLCache cache = client.cache;
final Store store = cache.store;
final cacheJson = jsonEncode(store.toMap());
return ServiceExtensionResponse.result(cacheJson);
});
final Client client = ...;
registerExtension('ext.gql_cache_lens.load', (_, __) async {
final Cache cache = client.cache;
final Store store = cache.store;
final cacheEntries = store.keys.map((k) => MapEntry(k, store.get(k)));
final cacheMap = Map.fromEntries(cacheEntries);
final cacheJson = jsonEncode(cacheMap);
return ServiceExtensionResponse.result(cacheJson);
});
Contributions are welcome! If you find a bug or have a feature request, please open an issue.
This project is licensed under the MIT License. See the LICENSE file for details.