Socket
Socket
Sign inDemoInstall

@8base/apollo-links

Package Overview
Dependencies
30
Maintainers
6
Versions
234
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @8base/apollo-links

A collection of Apollo links for more efficient communication with the 8base API.


Version published
Weekly downloads
1.3K
increased by77.43%
Maintainers
6
Install size
15.6 MB
Created
Weekly downloads
 

Readme

Source

A collection of Apollo links for more efficient communication with the 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 Used to refresh token parameters.
    • options.onAuthSuccess Function Callback which is executed when an attempt to refresh authentication is successful.
    • options.onAuthError Function? Callback which is executed when an attempt to refresh authentication fails.

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 { ApolloLink } from 'apollo-link';
import { BatchHttpLink } from 'apollo-link-batch-http';
import { getMainDefinition } from 'apollo-utilities';
import {
  AuthLink,
  FileUploadLink,
  SuccessLink,
} from '@8base/apollo-links';

const successHandler = ({ operation }) => {
  console.log(operation.getContext().someUsefulData);
};

const getAuthState = () => ({
  workspaceId: '',
  email: '',
  token: '',
});

const getRefreshTokenParameters = () => ({
  email: '',
  refreshToken: '',
});

const authSuccessHandler = ({ token, refreshToken}) => {
  console.log({ token, 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,
  }),
  ApolloLink.split(
    ({ query }) => {
      const definition = getMainDefinition(query);

      return (
        definition.kind === 'OperationDefinition' &&
        definition.operation === 'subscription'
      );
    },
    new SubscriptionLink({
      uri: 'wss://api-ws.8base.com',
      getAuthState: getAuthState,
      onAuthError: authErrorHandler,
    }),
    new BatchHttpLink({
      uri: 'https://api.8base.com',
    }),
  ),
])

FAQs

Last updated on 22 Mar 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc