FreshLink<T> class
A GraphQL Link which handles manages an authentication token automatically.
final freshLink = FreshLink.oAuth2(
tokenStorage: InMemoryTokenStorage<OAuth2Token>(),
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
-
FreshLink({required TokenStorage<
T> tokenStorage, required RefreshToken<T?> refreshToken, required ShouldRefresh shouldRefresh, TokenHeaderBuilder<T?> ? tokenHeader}) - 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 linkinherited -
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 theAuthenticationStatus.unauthenticated
if authenticationStatus not isAuthenticationStatus.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 providedtoken
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.