-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: init all from index, move http clients and messaging modules (
#939)
- Loading branch information
Showing
34 changed files
with
292 additions
and
280 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
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
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,5 @@ | ||
export const httpClient = { | ||
fetch: async (url: string): Promise<Response> => { | ||
return await fetch(url, { credentials: 'omit' }); | ||
}, | ||
}; |
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,68 @@ | ||
import { gql } from 'graphql-tag'; | ||
import { GraphQLClient } from 'graphql-request'; | ||
|
||
import { getOneOption } from '@commons/options'; | ||
|
||
import type { DeepNonNullable, DeepRequired } from '../typeUtils'; | ||
import { pontoonGraphQL } from '../apiEndpoints'; | ||
import type { | ||
GetProjectsInfoQuery, | ||
GetTeamsInfoQuery, | ||
} from '../../generated/pontoon.graphql'; | ||
import { getSdk } from '../../generated/pontoon.graphql'; | ||
|
||
const _getTeamsInfoQuery = gql` | ||
query getTeamsInfo { | ||
locales { | ||
code | ||
name | ||
approvedStrings | ||
pretranslatedStrings | ||
stringsWithWarnings | ||
stringsWithErrors | ||
missingStrings | ||
unreviewedStrings | ||
totalStrings | ||
} | ||
} | ||
`; | ||
|
||
interface GetTeamsInfoResponse { | ||
locales: DeepRequired<DeepNonNullable<GetTeamsInfoQuery['locales']>>; | ||
} | ||
|
||
const _getProjectsInfoQuery = gql` | ||
query getProjectsInfo { | ||
projects { | ||
slug | ||
name | ||
} | ||
} | ||
`; | ||
|
||
export interface GetProjectsInfoResponse { | ||
projects: DeepRequired<DeepNonNullable<GetProjectsInfoQuery['projects']>>; | ||
} | ||
|
||
function getGraphQLClient(pontoonBaseUrl: string) { | ||
return getSdk( | ||
new GraphQLClient(pontoonGraphQL(pontoonBaseUrl), { | ||
method: 'GET', | ||
}), | ||
); | ||
} | ||
|
||
async function getPontoonBaseUrl(): Promise<string> { | ||
return await getOneOption('pontoon_base_url'); | ||
} | ||
|
||
export const pontoonGraphqlClient = { | ||
getTeamsInfo: async (): Promise<GetTeamsInfoResponse> => { | ||
const client = getGraphQLClient(await getPontoonBaseUrl()); | ||
return (await client.getTeamsInfo()) as GetTeamsInfoResponse; | ||
}, | ||
getProjectsInfo: async (): Promise<GetProjectsInfoResponse> => { | ||
const client = getGraphQLClient(await getPontoonBaseUrl()); | ||
return (await client.getProjectsInfo()) as GetProjectsInfoResponse; | ||
}, | ||
}; |
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
Oops, something went wrong.