1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Flutter] Flutter - Retry token with graphql_flutter?

Discussão em 'Mobile' iniciado por Stack, Outubro 7, 2024 às 08:33.

  1. Stack

    Stack Membro Participativo

    I'm working with GraphQL (graphql_flutter) in Flutter and I want to handle token expiration by retrying the request with a new token. I've added ErrorLink to my setup but I'm unsure how to correctly make another API request to fetch the new token and update the GraphQL client.

    here is the code below

    import 'package:graphql_flutter/graphql_flutter.dart';


    final authLink = AuthLink(getToken: _getToken);


    final HttpLink httpLink = HttpLink(
    'https://testapi.com/graphql',
    );


    final ErrorLink errorLink = ErrorLink(
    // onGraphQLError: (req, forward, res) async* {
    // yield* forward(newReq);
    // },
    );


    //final Link link = errorLink.concat(authLink.concat(httpLink));
    final Link link = Link.from([authLink, httpLink]);


    final gqlClient = GraphQLClient(
    link: link,
    cache: GraphQLCache(store: InMemoryStore()),
    );


    Future<String?> _getToken() async {
    return 'Bearer token';
    }

    Continue reading...

Compartilhe esta Página