@8base/create-apollo-client 中文文档教程

发布于 3年前 浏览 26 更新于 3年前

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

返回 any 函数以通过

Table of Contents

CreateApolloLinksParams

createApolloLinks 选项的 jsonSchema 接口

创建 apollo 客户端类型:{uri: string, getAuthState: function (): AuthState?, 链接: {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?

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

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

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?

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();
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文