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
- [Properties](#properties)
- [Parameters](#parameters)
CreateApolloClientOptions
Interface of the createApolloClient configProperties
links
Array<ApolloLink>?connectToDevTools
boolean?defaultOptions
Object?queryDeduplication
any?ssrForceFetchDelay
any?ssrMode
any?
createApolloClient
Hight Order Function create apollo-client by the options.Parameters
config
CreateApolloClientOptions Config for create apollo client.
- `config.uri` Endpoint of the GraphQl server.
- `config.links` Array of the apollo links.
- `config.connectToDevTools` [Apolloclient option.](https://www.apollographql.com/docs/react/api/apollo-client.html#ApolloClientOptions)
- `config.defaultOptions` [Apolloclient option.](https://www.apollographql.com/docs/react/api/apollo-client.html#ApolloClientOptions)
- `config.queryDeduplication` [Apolloclient option.](https://www.apollographql.com/docs/react/api/apollo-client.html#ApolloClientOptions)
- `config.ssrForceFetchDelay` [Apolloclient option.](https://www.apollographql.com/docs/react/api/apollo-client.html#ApolloClientOptions)
- `config.ssrMode` [Apolloclient option.](https://www.apollographql.com/docs/react/api/apollo-client.html#ApolloClientOptions)
jsonSchema
Object with information about unions and interfaces.
Returns any Function to create apollo client by jsonSchema
createApolloLinks
Table of Contents
- [Properties](#properties)
- [Parameters](#parameters)
CreateApolloLinksParams
Interface of the createApolloLinks optionsType: {uri: string, getAuthState: function (): AuthState?, links: {tokenRefresh: GetTokenRefreshLinkParams?, fileUpload: {enable: boolean?}?, error: any?, batchHttp: {enable: boolean?}?}?}
Properties
uri
stringgetAuthState
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.](https://github.com/apollographql/apollo-link/tree/master/packages/apollo-link-batch-http)
- `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();