Skip to content

Commit

Permalink
feat: allow graphql for crowdin.com, add croql to listTmSegments (cro…
Browse files Browse the repository at this point in the history
  • Loading branch information
YHorodyskyi authored Jan 9, 2024
1 parent 3b4e456 commit 99645fa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
14 changes: 7 additions & 7 deletions src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,15 +254,15 @@ export abstract class CrowdinApi {
}

graphql<T>(req: { query: string; operationName?: string; variables?: any }): Promise<ResponseObject<T>> {
if (!this.organization) {
throw new Error('GraphQL API could be used only with Crowdin Enterprise.');
let url;

if (this.organization) {
url = `https://${this.organization}.api.crowdin.com/api/graphql`;
} else {
url = 'https://api.crowdin.com/api/graphql';
}

return this.post<ResponseObject<T>>(
`https://${this.organization}.api.crowdin.com/api/graphql`,
req,
this.defaultConfig(),
);
return this.post<ResponseObject<T>>(url, req, this.defaultConfig());
}

protected addQueryParam(url: string, name: string, value?: string | number): string {
Expand Down
12 changes: 10 additions & 2 deletions src/translationMemory/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,12 @@ export class TranslationMemory extends CrowdinApi {
* @param options optional paramerers for the request
* @see https://developer.crowdin.com/api/v2/#operation/api.tms.segments.getMany
*/
listTmSegments(tmId: number, options?: PaginationOptions): Promise<ResponseList<TranslationMemoryModel.TMSegment>> {
const url = `${this.url}/tms/${tmId}/segments`;
listTmSegments(
tmId: number,
options?: TranslationMemoryModel.ListSegmentsOptions,
): Promise<ResponseList<TranslationMemoryModel.TMSegment>> {
let url = `${this.url}/tms/${tmId}/segments`;
url = this.addQueryParam(url, 'croql', options?.croql);
return this.getList(url, options?.limit, options?.offset);
}

Expand Down Expand Up @@ -358,6 +362,10 @@ export namespace TranslationMemoryModel {
userId?: number;
}

export interface ListSegmentsOptions extends PaginationOptions {
croql?: string;
}

export interface TMSegment {
id: number;
records: TMSegmentRecord[];
Expand Down

0 comments on commit 99645fa

Please sign in to comment.