-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
8,124 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
EAS_PROJECT_ID="" | ||
APP_NAME="Dev" | ||
|
||
API_URL="" | ||
|
||
SENTRY_DSN="" | ||
SENTRY_ORG="" | ||
SENTRY_PROJECT="" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
EAS_PROJECT_ID="" | ||
APP_NAME="RN Starter" | ||
|
||
API_URL="" | ||
|
||
SENTRY_DSN="" | ||
SENTRY_ORG="" | ||
SENTRY_PROJECT="" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
EAS_PROJECT_ID="" | ||
APP_NAME="Staging" | ||
|
||
API_URL="" | ||
|
||
SENTRY_DSN="" | ||
SENTRY_ORG="" | ||
SENTRY_PROJECT="" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import type { CodegenConfig } from '@graphql-codegen/cli'; | ||
|
||
const config: CodegenConfig = { | ||
overwrite: true, | ||
schema: 'https://graphqlzero.almansi.me/api', | ||
documents: 'src/**/*.tsx', | ||
generates: { | ||
// 'src/gql/generated/types.ts': { | ||
// plugins: ['typescript'], | ||
// config: { | ||
// enumsAsTypes: true, | ||
// disableDescriptions: true, | ||
// strictScalars: true, | ||
// defaultScalarType: 'unknown', | ||
// scalars: { | ||
// Date: 'string', | ||
// DateTime: 'string', | ||
// }, | ||
// }, | ||
// }, | ||
'src/gql/generated/': { | ||
preset: 'client', | ||
}, | ||
'src/gql/generated/hooks.ts': { | ||
plugins: [ | ||
'typescript', | ||
'typescript-operations', | ||
'typescript-react-query', | ||
], | ||
config: { | ||
reactQueryVersion: 5, | ||
exposeQueryKeys: true, | ||
exposeFetcher: true, | ||
fetcher: '../../core/api/request#request', | ||
}, | ||
}, | ||
'src/gql/graphql.schema.json': { | ||
plugins: ['introspection'], | ||
}, | ||
}, | ||
hooks: { | ||
afterAllFileWrite: [ | ||
"eslint ./src/gql --ext .ts,.json --fix && yarn prettier --write './src/gql/**/*.ts'", | ||
], | ||
}, | ||
}; | ||
|
||
export default config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { createAsyncStoragePersister } from '@tanstack/query-async-storage-persister'; | ||
import { QueryClient } from '@tanstack/react-query'; | ||
import type { PersistQueryClientOptions } from '@tanstack/react-query-persist-client'; | ||
|
||
import { storageKeys } from '$core/constants'; | ||
import { QueryClientStorage } from '$core/storage'; | ||
|
||
import { | ||
GC_TIME, | ||
STALE_TIME, | ||
THIRTY_DAYS, | ||
retryDelay, | ||
} from './utils/queryClient.utils'; | ||
|
||
const asyncStoragePersister = createAsyncStoragePersister({ | ||
key: storageKeys.queryStorage.id, | ||
storage: QueryClientStorage, | ||
}); | ||
|
||
export const persistOptions: Omit<PersistQueryClientOptions, 'queryClient'> = { | ||
persister: asyncStoragePersister, | ||
buster: 'v1', | ||
maxAge: THIRTY_DAYS, | ||
}; | ||
|
||
export const queryClient = new QueryClient({ | ||
defaultOptions: { | ||
queries: { | ||
retryDelay, | ||
staleTime: STALE_TIME, // 5 minutes | ||
gcTime: GC_TIME, // 24 hours | ||
refetchOnWindowFocus: false, | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { GraphQLClient } from 'graphql-request'; | ||
import type { | ||
GraphQLClientRequestHeaders, | ||
Variables, | ||
} from 'graphql-request/build/esm/types'; | ||
import i18next from 'i18next'; | ||
import memoize from 'lodash/memoize'; | ||
|
||
import { config } from '$core/constants'; | ||
import { getCurrentLocale } from '$core/i18n/utils/getCurrentLocale'; | ||
|
||
import { getAppIdentifier } from './utils/request.utils'; | ||
|
||
const getClientEndpoint = (env: string) => | ||
`${env}?lang=${getCurrentLocale(i18next)}`; | ||
|
||
const getQueryClient = memoize( | ||
(env: string) => new GraphQLClient(getClientEndpoint(env)), | ||
(...args) => args.join('_'), | ||
); | ||
|
||
let client: GraphQLClient | undefined; | ||
|
||
export const request = | ||
<TData, TVariables extends Variables>( | ||
query: string, | ||
variables?: TVariables, | ||
options?: GraphQLClientRequestHeaders, | ||
): (() => Promise<TData>) => | ||
async () => { | ||
client = getQueryClient(config.apiURL); | ||
client.setEndpoint(getClientEndpoint(config.apiURL)); | ||
|
||
if (options) client.setHeaders(options); | ||
client.setHeader('app-id', getAppIdentifier()); | ||
client.setHeader('app-version', config.version); | ||
|
||
return client.request(query, variables); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* eslint-disable @typescript-eslint/no-magic-numbers */ | ||
|
||
const ONE_SECOND = 1_000; | ||
const MAX_RETRY_DELAY = 30_000; | ||
const FIVE_MINUTES = 1000 * 60 * 5; | ||
const TWENTY_FOUR_HOURS = 1000 * 60 * 60 * 24; | ||
|
||
export const THIRTY_DAYS = 30 * TWENTY_FOUR_HOURS; | ||
|
||
export const retryDelay = (attemptIndex: number) => | ||
Math.min(ONE_SECOND * 2 ** attemptIndex, MAX_RETRY_DELAY); | ||
|
||
export const STALE_TIME = FIVE_MINUTES; | ||
export const GC_TIME = TWENTY_FOUR_HOURS; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Platform } from 'react-native'; | ||
|
||
import { config } from '$core/constants'; | ||
|
||
export function getAppIdentifier() { | ||
// com.tsyirvo.rnstarter/2.0.0(777)_ios | ||
return `${config.bundleId}/${config.version}${config.buildNumber ? `(${config.buildNumber})` : ''}_${Platform.OS}`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
export const storageKeys = { | ||
appStorage: { | ||
id: 'app-storage', | ||
locale: 'app.locale', | ||
}, | ||
queryStorage: { | ||
id: 'query-storage', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import type { i18n } from 'i18next'; | ||
|
||
import { config } from '$core/constants'; | ||
|
||
export const getCurrentLocale = (i18n: i18n) => { | ||
const languageCode = i18n.language; | ||
const [primaryCode] = languageCode.split('-'); | ||
|
||
if (i18n.hasResourceBundle(languageCode, 'common')) { | ||
return languageCode; | ||
} else if (primaryCode && i18n.hasResourceBundle(primaryCode, 'common')) { | ||
return primaryCode; | ||
} | ||
|
||
return config.defaultLocale; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import { MMKV } from 'react-native-mmkv'; | ||
|
||
import { storageKeys } from '$core/constants'; | ||
|
||
export const AppStorage = new MMKV({ | ||
id: 'app-storage', | ||
id: storageKeys.appStorage.id, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export { AppStorage } from './appStorage'; | ||
export { QueryClientStorage } from './queryClientStorage'; |
Oops, something went wrong.