Skip to content

A Flutter DevTools Extension for inspecting GraphQL cache

License

Notifications You must be signed in to change notification settings

temoki/gql_cache_lens

Repository files navigation

gql_cache_lens

A Flutter DevTools extension for inspecting GraphQL cache

Features

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

Supported GraphQL Packages

Currently, gql_cache_lens supports the following GraphQL packages:

Screenshots

Installation

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

Usage

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.

For graphql package

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);
});

For ferry package

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);
});

Contributing

Contributions are welcome! If you find a bug or have a feature request, please open an issue.

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

A Flutter DevTools Extension for inspecting GraphQL cache

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages