import 'package:graphql_flutter/graphql_flutter.dart'; import 'package:shared_preferences/shared_preferences.dart'; /// Configure and provide the GraphQL client. /// Set [kGraphQLEndpoint] to your Magento GraphQL endpoint. const String kGraphQLEndpoint = String.fromEnvironment( 'GRAPHQL_ENDPOINT', defaultValue: 'https://your-magento-store.com/graphql', ); Future buildGraphQLClient() async { await initHiveForFlutter(); final prefs = await SharedPreferences.getInstance(); final token = prefs.getString('auth_token') ?? ''; final authLink = AuthLink(getToken: () async => token.isNotEmpty ? 'Bearer $token' : ''); final httpLink = HttpLink(kGraphQLEndpoint); final link = authLink.concat(httpLink); return GraphQLClient( link: link, cache: GraphQLCache(store: HiveStore()), ); } ValueNotifier buildGraphQLClientNotifier(GraphQLClient client) { return ValueNotifier(client); }