Skip to content

Commit

Permalink
Replace graphql client with http POST
Browse files Browse the repository at this point in the history
  • Loading branch information
silvadenisaraujo committed Sep 6, 2024
1 parent 18d5f4e commit 1c7435c
Show file tree
Hide file tree
Showing 4 changed files with 1,273 additions and 1,866 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"ts-jest": "^25.2.1",
"ts-node": "^8",
"typescript": "^3.9.7",
"vtex": "^2.128.0"
"vtex": "4.1.0"
},
"engines": {
"node": ">=8.0.0"
Expand Down
39 changes: 19 additions & 20 deletions src/clients/apps/Rewriter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AppGraphQLClient, InstanceOptions, IOContext } from '@vtex/api'
import type { InstanceOptions, IOContext } from '@vtex/api'
import { AppGraphQLClient } from '@vtex/api'
import { IOClientFactory } from 'vtex'

export interface RedirectInput {
Expand Down Expand Up @@ -40,32 +41,30 @@ export class Rewriter extends AppGraphQLClient {
}

public exportRedirects = (next?: string): Promise<ExportResponse> =>
this.graphql
.query<{ redirect: { listRedirects: ExportResponse } }, { next?: string }>(
this.http
.post<{ data: { redirect: { listRedirects: ExportResponse } } }>(
'',
{
query: `
query ListRedirects($next: String) {
redirect {
listRedirects(next: $next) {
next
routes {
binding
from
to
type
endDate
}
}
}
}
`,
query: `query ListRedirects($next: String) {
redirect {
listRedirects(next: $next) {
next
routes {
from
to
type
endDate
}
}
}
}`,
variables: { next },
},
{
metric: 'rewriter-get-redirects',
}
)
.then((res) => res.data?.redirect?.listRedirects) as Promise<ExportResponse>
.then((res) => res.data.redirect?.listRedirects) as Promise<ExportResponse>

public importRedirects = (routes: RedirectInput[]): Promise<boolean> =>
this.graphql
Expand Down
3 changes: 2 additions & 1 deletion src/modules/rewriter/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { readJson, writeFile } from 'fs-extra'
import { Parser } from 'json2csv'
import ora from 'ora'
import { createInterface } from 'readline'
import { Redirect, Rewriter } from '../../clients/apps/Rewriter'
import type { Redirect } from '../../clients/apps/Rewriter'
import { Rewriter } from '../../clients/apps/Rewriter'
import { SessionManager, logger, isVerbose } from 'vtex'
import {
deleteMetainfo,
Expand Down
Loading

0 comments on commit 1c7435c

Please sign in to comment.