Skip to content

Commit

Permalink
fix(graphql): register extension only for not release mode and not al…
Browse files Browse the repository at this point in the history
…ready registered
  • Loading branch information
lllttt06 committed Aug 1, 2024
1 parent 5454a4e commit 1f0f5d4
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions packages/graphql/lib/src/graphql_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import 'package:graphql/src/cache/cache.dart';

import 'package:graphql/src/core/fetch_more.dart';

/// Flag to register extension only once
bool _isExtensionRegistered = false;

/// Universal GraphQL Client with configurable caching and [link][] system.
/// modelled after the [`apollo-client`][ac].
///
Expand All @@ -35,14 +38,19 @@ class GraphQLClient implements GraphQLDataProxy {
cache: cache,
alwaysRebroadcast: alwaysRebroadcast,
) {
// Register the extension to expose the cache to the devtools
registerExtension(
'ext.graphql.getCache',
(method, parameters) async {
return ServiceExtensionResponse.result(
jsonEncode({'value': this.cache.store.toMap()}));
},
);
const releaseMode = bool.fromEnvironment('dart.vm.product');
// Register extension for not in release mode and not already registered
if (!releaseMode && !_isExtensionRegistered) {
// Register the extension to expose the cache to the devtools
registerExtension(
'ext.graphql.getCache',
(method, parameters) async {
return ServiceExtensionResponse.result(
jsonEncode({'value': this.cache.store.toMap()}));
},
);
_isExtensionRegistered = true;
}
}

/// The default [Policies] to set for each client action
Expand Down

0 comments on commit 1f0f5d4

Please sign in to comment.