@8base/create-apollo-client

The Create Apollo Client library contains factory to create original [ApolloClient](https://www.apollographql.com/docs/react/api/apollo-client.html) and several links to work with 8base services.

Stats

stars 🌟issues ⚠️updated 🛠created 🐣size 🏋️‍♀️
@8base/create-apollo-client
Minified + gzip package size for @8base/create-apollo-client in KB

Readme

8base Create Apollo Client

The Create Apollo Client library contains factory to create original ApolloClient and several links to work with 8base services.

createApolloClient

Table of Contents

CreateApolloClientOptions

Interface of the createApolloClient config

Properties

  • links Array<ApolloLink>?
  • connectToDevTools boolean?
  • defaultOptions Object?
  • queryDeduplication any?
  • ssrForceFetchDelay any?
  • ssrMode any?

createApolloClient

Hight Order Function create apollo-client by the options.

Parameters

Returns any Function to create apollo client by jsonSchema

createApolloLinks

Table of Contents

CreateApolloLinksParams

Interface of the createApolloLinks options

Type: {uri: string, getAuthState: function (): AuthState?, links: {tokenRefresh: GetTokenRefreshLinkParams?, fileUpload: {enable: boolean?}?, error: any?, batchHttp: {enable: boolean?}?}?}

Properties

  • uri string
  • getAuthState function (): AuthState?
  • links {tokenRefresh: GetTokenRefreshLinkParams?, fileUpload: {enable: boolean?}?, error: any?, batchHttp: {enable: boolean?}?}?
  • links.tokenRefresh GetTokenRefreshLinkParams?
  • links.fileUpload {enable: boolean?}?
  • links.fileUpload.enable boolean?
  • links.error any?
  • links.batchHttp {enable: boolean?}?
  • links.batchHttp.enable boolean?

createApolloLinks

Creates apollo links for the 8base backend service.

Parameters

  • config CreateApolloLinksParams Options to create apollo links.
    • config.getAuthState Function to return the application auth state. Needs for the auth links.
    • config.uri Endpoint of the 8base backend.
    • config.link Links settings.
      • config.link.tokenRefresh Options to configure token refresh links which update auth tokens.
        • config.link.tokenRefresh.enable When true then enable link. (optional, default true)
        • config.link.tokenRefresh.onUpdateTokenFail Callback executed on token update fail.
        • config.link.tokenRefresh.onUpdateTokenSuccess Callback executed on token update successfully completes.
        • config.link.tokenRefresh.onIdTokenExpired Callback executed on expired id token.
      • config.link.fileUpload Options to configure upload link which loads files on amazon s3.
        • config.link.fileUpload.enable When true then enable link. (optional, default true)
      • config.link.auth Options to configure auth link which add the headers to the request.
        • config.link.auth.enable When true then enable link. (optional, default true)
      • config.link.error Options to configure error link which pass errors by the callbacks.
        • config.link.error.enable When true then enable link. (optional, default true)
        • config.link.error.onGraphQLErrors Callback executed on request fail with graphql error.
        • config.link.error.onNetworkError Callback executed on request fail with network error.
      • config.link.batchHttp Options to configure batch http link.
        • config.link.batchHttp.enable When true then enable link. (optional, default true)

Usage

const getAuthState = () => ({
  email: 'user-name@gmail.com',
  accountId: 'account-id-bcxcvboiet',
  organizationId: 'organization-id-142',
  refreshToken: 'refresh-token-asdasdafaqwebfdhgh,dlphgkmw092y09qkefskbnq0921r',
  idToken: 'id-token-glhjkoerjhyldkmn;vjioghlblafeorhn',
});

const links = createApolloLinks({
  getAuthState,
  uri: 'https://prestaging-api.8basedev.com',
  links: {},
});

const getApolloClient = createApolloClient({ links });

cons apolloClient = getApolloClient();

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.