import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:graphql/client.dart';

import '../app/constant.dart';

final graphqlProvider = Provider.family<GraphQLClient, String>(
  (_, token) {
    final policies = Policies(
      fetch: FetchPolicy.noCache,
    );
    return GraphQLClient(
      link: (token != "")
          ? HttpLink(
              Constant.baseURLGraphQl,
              defaultHeaders: {
                'Authorization': 'Bearer $token',
              },
            )
          : HttpLink(
              Constant.baseURLGraphQl,
            ),
      cache: GraphQLCache(),
      defaultPolicies: DefaultPolicies(
        watchQuery: policies,
        query: policies,
        mutate: policies,
      ),
    );
  },
);
