Skip to content

Commit 1c7435c

Browse files
Replace graphql client with http POST
1 parent 18d5f4e commit 1c7435c

File tree

4 files changed

+1273
-1866
lines changed

4 files changed

+1273
-1866
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"ts-jest": "^25.2.1",
4242
"ts-node": "^8",
4343
"typescript": "^3.9.7",
44-
"vtex": "^2.128.0"
44+
"vtex": "4.1.0"
4545
},
4646
"engines": {
4747
"node": ">=8.0.0"

src/clients/apps/Rewriter.ts

+19-20
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { AppGraphQLClient, InstanceOptions, IOContext } from '@vtex/api'
1+
import type { InstanceOptions, IOContext } from '@vtex/api'
2+
import { AppGraphQLClient } from '@vtex/api'
23
import { IOClientFactory } from 'vtex'
34

45
export interface RedirectInput {
@@ -40,32 +41,30 @@ export class Rewriter extends AppGraphQLClient {
4041
}
4142

4243
public exportRedirects = (next?: string): Promise<ExportResponse> =>
43-
this.graphql
44-
.query<{ redirect: { listRedirects: ExportResponse } }, { next?: string }>(
44+
this.http
45+
.post<{ data: { redirect: { listRedirects: ExportResponse } } }>(
46+
'',
4547
{
46-
query: `
47-
query ListRedirects($next: String) {
48-
redirect {
49-
listRedirects(next: $next) {
50-
next
51-
routes {
52-
binding
53-
from
54-
to
55-
type
56-
endDate
57-
}
58-
}
59-
}
60-
}
61-
`,
48+
query: `query ListRedirects($next: String) {
49+
redirect {
50+
listRedirects(next: $next) {
51+
next
52+
routes {
53+
from
54+
to
55+
type
56+
endDate
57+
}
58+
}
59+
}
60+
}`,
6261
variables: { next },
6362
},
6463
{
6564
metric: 'rewriter-get-redirects',
6665
}
6766
)
68-
.then((res) => res.data?.redirect?.listRedirects) as Promise<ExportResponse>
67+
.then((res) => res.data.redirect?.listRedirects) as Promise<ExportResponse>
6968

7069
public importRedirects = (routes: RedirectInput[]): Promise<boolean> =>
7170
this.graphql

src/modules/rewriter/export.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { readJson, writeFile } from 'fs-extra'
33
import { Parser } from 'json2csv'
44
import ora from 'ora'
55
import { createInterface } from 'readline'
6-
import { Redirect, Rewriter } from '../../clients/apps/Rewriter'
6+
import type { Redirect } from '../../clients/apps/Rewriter'
7+
import { Rewriter } from '../../clients/apps/Rewriter'
78
import { SessionManager, logger, isVerbose } from 'vtex'
89
import {
910
deleteMetainfo,

0 commit comments

Comments
 (0)