fresh_graphql 0.2.0 copy "fresh_graphql: ^0.2.0" to clipboard
fresh_graphql: ^0.2.0 copied to clipboard

outdated

An graphql link for token refresh. Built on top of package:graphql and manages authentication tokens transparently.

example/main.dart

import 'dart:io';
import 'dart:math';

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

const getJobsQuery = r'''
  query GetJobs() {
    jobs {
      title
    }
  }
''';

void main() async {
  final freshLink = FreshLink<OAuth2Token>(
    tokenStorage: InMemoryTokenStorage(),
    refreshToken: (token, client) async {
      // Perform refresh and return new token
      print('refreshing token!');
      await Future.delayed(const Duration(seconds: 1));
      if (Random().nextInt(3) == 0) {
        throw RevokeTokenException();
      }
      return OAuth2Token(accessToken: 't0ps3cret_r3fresh3d!');
    },
    shouldRefresh: (_) => Random().nextInt(1) == 0,
  )
    ..setToken(OAuth2Token(accessToken: 't0ps3cret!'))
    ..authenticationStatus.listen(print);
  final graphQLClient = GraphQLClient(
    cache: InMemoryCache(),
    link: Link.from([freshLink, HttpLink(uri: 'https://api.graphql.jobs')]),
  );
  final result = await graphQLClient.query(
    QueryOptions(documentNode: gql(getJobsQuery)),
  );
  print(result.data);
  exit(0);
}
32
likes
0
pub points
87%
popularity

Publisher

verified publisherfelangel.dev

An graphql link for token refresh. Built on top of package:graphql and manages authentication tokens transparently.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

fresh, graphql, http, meta, pedantic

More

Packages that depend on fresh_graphql