UNPKG

@appello/services

Version:

Services package with api / graphql

35 lines (34 loc) 1.47 kB
import { ApolloClient, ApolloLink, InMemoryCacheConfig } from '@apollo/client'; import { AnyObject, Nillable, Nullable, Unidentifiable } from '@appello/common'; import createUploadLink from 'apollo-upload-client/createUploadLink.mjs'; import { ClientOptions } from 'graphql-ws/lib/client'; import { GqlErrorCodeEnum } from './consts'; export interface GqlClientContext { headers?: Record<string, unknown>; withoutAuth?: boolean; } export interface GqlErrorResponse { code: GqlErrorCodeEnum; explain?: Record<string, string>; } export interface GqlBaseTokens { accessToken: string; refreshToken: string; } export interface GqlClientConfig<T extends AnyObject = GqlBaseTokens> { url: string; getAccessToken: () => Promise<Nillable<string>> | Nillable<string>; getRefreshToken: () => Promise<Nillable<string>> | Nillable<string>; onTokenRefreshSuccess: (tokens: T) => void; onTokenRefreshError: (error?: unknown) => void; refreshTokens: (client: ApolloClient<unknown>, context: GqlClientContext) => Promise<Unidentifiable<Nullable<T>>>; wsUrl?: string; wsLnkParams?: ClientOptions; onUnknownError?: (message: string) => void; getAccessTokenFromContext?: (context: AnyObject) => string; refreshTokenErrorMessage?: string; refreshTokenOperationName?: string; cache?: InMemoryCacheConfig; additionalLinks?: ApolloLink | ApolloLink[]; uploadLinkParams?: Parameters<typeof createUploadLink>[0]; }