diff --git a/packages/graphql/lib/src/graphql_client.dart b/packages/graphql/lib/src/graphql_client.dart index 04098097..37a5fb3f 100644 --- a/packages/graphql/lib/src/graphql_client.dart +++ b/packages/graphql/lib/src/graphql_client.dart @@ -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]. /// @@ -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