0.1.5 • Published 7 years ago
@8base/create-apollo-client v0.1.5
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
linksArray<ApolloLink>?connectToDevToolsboolean?defaultOptionsObject?queryDeduplicationany?ssrForceFetchDelayany?ssrModeany?
createApolloClient
Hight Order Function create apollo-client by the options.
Parameters
configCreateApolloClientOptions Config for create apollo client.config.uriEndpoint of the GraphQl server.config.linksArray of the apollo links.config.connectToDevToolsApolloclient option.config.defaultOptionsApolloclient option.config.queryDeduplicationApolloclient option.config.ssrForceFetchDelayApolloclient option.config.ssrModeApolloclient option.
jsonSchemaObject with information about unions and interfaces.
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
uristringgetAuthStatefunction (): AuthState?links{tokenRefresh: GetTokenRefreshLinkParams?, fileUpload: {enable: boolean?}?, error: any?, batchHttp: {enable: boolean?}?}?links.tokenRefreshGetTokenRefreshLinkParams?links.fileUpload{enable: boolean?}?links.fileUpload.enableboolean?links.errorany?links.batchHttp{enable: boolean?}?links.batchHttp.enableboolean?
createApolloLinks
Creates apollo links for the 8base backend service.
Parameters
configCreateApolloLinksParams Options to create apollo links.config.getAuthStateFunction to return the application auth state. Needs for the auth links.config.uriEndpoint of the 8base backend.config.linkLinks settings.config.link.tokenRefreshOptions to configure token refresh links which update auth tokens.config.link.tokenRefresh.enableWhen true then enable link. (optional, defaulttrue)config.link.tokenRefresh.onUpdateTokenFailCallback executed on token update fail.config.link.tokenRefresh.onUpdateTokenSuccessCallback executed on token update successfully completes.config.link.tokenRefresh.onIdTokenExpiredCallback executed on expired id token.
config.link.fileUploadOptions to configure upload link which loads files on amazon s3.config.link.fileUpload.enableWhen true then enable link. (optional, defaulttrue)
config.link.authOptions to configure auth link which add the headers to the request.config.link.auth.enableWhen true then enable link. (optional, defaulttrue)
config.link.errorOptions to configure error link which pass errors by the callbacks.config.link.error.enableWhen true then enable link. (optional, defaulttrue)config.link.error.onGraphQLErrorsCallback executed on request fail with graphql error.config.link.error.onNetworkErrorCallback executed on request fail with network error.
config.link.batchHttpOptions to configure batch http link.config.link.batchHttp.enableWhen true then enable link. (optional, defaulttrue)
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();