@8base/create-apollo-client 中文文档教程
8base Create Apollo Client
Create Apollo Client 库包含用于创建原始 ApolloClient 的工厂和用于使用 8base 的几个链接服务。
createApolloClient
Table of Contents
CreateApolloClientOptions
createApolloClient 配置
Properties
links
Array<ApolloLink>?connectToDevTools
boolean?defaultOptions
Object?queryDeduplication
any?ssrForceFetchDelay
any?ssrMode
any?
createApolloClient
高阶函数的接口通过选项创建 apollo-client。
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.config.defaultOptions
Apolloclient option.config.queryDeduplication
Apolloclient option.config.ssrForceFetchDelay
Apolloclient option.config.ssrMode
Apolloclient option.
jsonSchema
Object with information about unions and interfaces.
返回 any 函数以通过
createApolloLinks
Table of Contents
CreateApolloLinksParams
createApolloLinks 选项的 jsonSchema 接口
创建 apollo 客户端类型:{uri: string, getAuthState: function (): AuthState?, 链接: {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
为 8base 后端服务创建 apollo 链接。
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, defaulttrue
)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, defaulttrue
)
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, defaulttrue
)
config.link.error
Options to configure error link which pass errors by the callbacks.config.link.error.enable
When true then enable link. (optional, defaulttrue
)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, 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();
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
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.config.defaultOptions
Apolloclient option.config.queryDeduplication
Apolloclient option.config.ssrForceFetchDelay
Apolloclient option.config.ssrMode
Apolloclient option.
jsonSchema
Object 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
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, defaulttrue
)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, defaulttrue
)
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, defaulttrue
)
config.link.error
Options to configure error link which pass errors by the callbacks.config.link.error.enable
When true then enable link. (optional, defaulttrue
)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, 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();