This package has been deprecated

Author message:

This package was moved to @8base/apollo-client package. Use it instead.

@8base/create-apollo-client

0.1.5 • Public • Published

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();

Readme

Keywords

none

Package Sidebar

Install

npm i @8base/create-apollo-client

Weekly Downloads

1

Version

0.1.5

License

MIT

Unpacked Size

228 kB

Total Files

8

Last publish

Collaborators

  • dav1nx1
  • jorge.osorio
  • 8base-bot