8base Apollo Links
The set of Apollo links for more useful communication with 8base API.
API
Table of Contents
TokenRefreshLink
Extends ApolloLink
Token Refresh Link renew authentication token when it's expired.
Parameters
options
TokenRefreshLinkOptions The token refresh link options.
options.getRefreshTokenParameters
Function The function which are using for get refresh token parameters.options.onAuthSuccess
Function The callback which called when attempt to refresh authentication is success.options.onAuthError
Function? The callback which called when attempt to refresh authentication is failed.
SuccessLink
SuccessLink calls handler on every successful operation.
Parameters
successHandler
Function success handler.
Handler
Success handler takes the following parameters:
operation
Operation apollo graphql operation.
Usage
import {
AuthLink,
FileUploadLink,
SuccessLink,
} from '@8base/apollo-links';
const successHandler = ({ operation }) => {
console.log(operation.getContext().someUsefulData);
};
const getAuthState = () => ({
workaspace: '',
email: '',
userId: '',
idToken: '',
refreshToken: '',
});
const getRefreshTokenParameters = () => ({
email: '',
refreshToken: '',
});
const authSuccessHandler = ({ idToken, refreshToken}) => {
conolse.log({ idToken, refreshToken });
}
const authErrorHandler = () => {
console.log('Auth error');
}
const links = ApolloLink.from([
new FileUploadLink(),
new SuccessLink(successHandler),
new AuthLink({
getAuthState: getAuthState,
getRefreshTokenParameters: getRefreshTokenParameters,
onAuthSuccess: authSuccessHandler,
onAuthError: authErrorHandler,
}),
])