Skip to content

Commit

Permalink
Merge pull request #6 from vtex/bugfix/error-on-export
Browse files Browse the repository at this point in the history
Replace graphql client with http POST
  • Loading branch information
silvadenisaraujo authored Sep 10, 2024
2 parents 18d5f4e + dc43fdb commit 456fb11
Show file tree
Hide file tree
Showing 10 changed files with 1,292 additions and 1,881 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12
node-version: 20
- run: yarn install --ignore-scripts
- run: yarn run ci:prettier-check
- run: yarn run lint
Expand All @@ -25,7 +25,7 @@ jobs:
strategy:
fail-fast: true
matrix:
node-version: [12]
node-version: [20]
os: [ubuntu-latest, windows-latest, macOS-latest]

steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/plugin-documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Set up Node.js
uses: actions/setup-node@v1
with:
node-version: 12.x
node-version: 20.x
- name: Install dependencies
run: yarn install
- name: Update README
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-prerelease-npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12
node-version: 20
registry-url: https://registry.npmjs.org/
- run: yarn install --ignore-scripts
- run: yarn build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-stable-npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12
node-version: 20
registry-url: https://registry.npmjs.org/
- run: yarn install --ignore-scripts
- run: yarn build
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- Use http POST instead of graphql client to list redirects

## [1.0.0] - 2021-07-12

### Fixed
Expand Down
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ $ npm install -g @vtex/cli-plugin-redirects
$ oclif-example COMMAND
running command...
$ oclif-example (-v|--version|version)
@vtex/cli-plugin-redirects/1.0.0 linux-x64 node-v12.22.1
@vtex/cli-plugin-redirects/1.0.0 linux-x64 node-v20.17.0
$ oclif-example --help [COMMAND]
USAGE
$ oclif-example COMMAND
Expand All @@ -58,9 +58,9 @@ ARGUMENTS
CSVPATH CSV file containing the URL paths to delete.
OPTIONS
-h, --help show CLI help
-v, --verbose Show debug level logs
--trace Ensure all requests to VTEX IO are traced
-h, --help Shows this help message.
-v, --verbose Shows debug level logs.
--trace Ensures all requests to VTEX IO are traced.
EXAMPLE
vtex redirects delete csvPath
Expand All @@ -80,9 +80,9 @@ ARGUMENTS
CSVPATH Name of the CSV file.
OPTIONS
-h, --help show CLI help
-v, --verbose Show debug level logs
--trace Ensure all requests to VTEX IO are traced
-h, --help Shows this help message.
-v, --verbose Shows debug level logs.
--trace Ensures all requests to VTEX IO are traced.
EXAMPLE
vtex redirects export csvPath
Expand All @@ -102,10 +102,10 @@ ARGUMENTS
CSVPATH Name of the CSV file.
OPTIONS
-h, --help show CLI help
-h, --help Shows this help message.
-r, --reset Removes all redirects previously defined.
-v, --verbose Show debug level logs
--trace Ensure all requests to VTEX IO are traced
-v, --verbose Shows debug level logs.
--trace Ensures all requests to VTEX IO are traced.
EXAMPLE
vtex redirects import csvPath
Expand Down
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 456fb11

Please sign in to comment.