FreshLink<T> class

A GraphQL Link which handles manages an authentication token automatically.

A constructor that returns a Fresh interceptor that uses the OAuth2Token token, the standard token class and define the` tokenHeader as 'authorization': '${token.tokenType} ${token.accessToken}'

final freshLink = FreshLink(
  tokenStorage: InMemoryTokenStorage(),
  refreshToken: (token, client) {
    // Perform refresh and return new token
  },
);
final graphQLClient = GraphQLClient(
  cache: InMemoryCache(),
  link: Link.from([freshLink, HttpLink(uri: 'https://my.graphql.api')]),
);

Constructors

A GraphQL Link which handles manages an authentication token automatically.

Properties

authenticationStatus Stream<AuthenticationStatus>
Returns a Stream<AuthenticationStatus> which can be used to get notified of changes to the authentication state based on the presence/absence of a token.
no setterinherited
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
token Future<T?>
Returns the current token.
no setterinherited
tokenStorage TokenStorage<T>
Setter for the TokenStorage instance.
no getterinherited

Methods

clearToken() Future<void>
Clears token storage and updates the AuthenticationStatus to AuthenticationStatus.unauthenticated.
inherited
close() Future<void>
Closes Fresh StreamController.
inherited
concat(Link next) → Link
Adds next after this link
inherited
dispose() Future<void>
Can be called to clean up resources
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
request(Request request, [NextLink? forward]) Stream<Response>
A function called when a request reaches this Link
revokeToken() Future<void>
Delete the storaged token. and emit the AuthenticationStatus.unauthenticated if authenticationStatus not is AuthenticationStatus.unauthenticated This method should be called when the token is no longer valid.
inherited
route(LinkRouter route) → Link
Route requests after this link
inherited
setToken(T? token) Future<void>
Sets the internal token to the provided token and updates the AuthenticationStatus accordingly.
inherited
split(bool test(Request request), Link left, [Link right = const PassthroughLink()]) → Link
Split requests after this link
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

oAuth2({required TokenStorage<OAuth2Token> tokenStorage, required RefreshToken<OAuth2Token?> refreshToken, required ShouldRefresh shouldRefresh, TokenHeaderBuilder<OAuth2Token?>? tokenHeader}) FreshLink<OAuth2Token>
A GraphQL Link which handles manages an authentication token automatically.