Skip to content

Commit ab2a18b

Browse files
authored
Merge pull request #215 from Web3-API/revert-186-mmuftic/http-plugin-upgrade
Revert "HTTP plugin upgrade"
2 parents 3dd9364 + 2428c5d commit ab2a18b

6 files changed

Lines changed: 18 additions & 23 deletions

File tree

packages/js/plugins/http/schema.graphql

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@ type Response {
1818
type Request {
1919
headers: [Header!]
2020
urlParams: [UrlParam!]
21-
responseType: ResponseType!
21+
responseType: String! # "TEXT" || "BINARY"
2222
body: String
2323
}
2424

25-
enum ResponseType {
26-
TEXT
27-
BINARY
28-
}
25+
# Enum types curently not supported
26+
#
27+
# enum ResponseType {
28+
# TEXT
29+
# BINARY
30+
# }
2931

3032
type Query {
3133
get(url: String!, request: Request): Response

packages/js/plugins/http/src/__tests__/e2e/e2e.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ describe("e2e tests for HttpPlugin", () => {
251251
post(
252252
url: "http://www.example.com/api"
253253
request: {
254-
responseType: 1
254+
responseType: BINARY
255255
body: "{data: 'test-request'}"
256256
}
257257
)
@@ -293,7 +293,7 @@ describe("e2e tests for HttpPlugin", () => {
293293
post(
294294
url: "http://www.example.com/api"
295295
request: {
296-
responseType: 0
296+
responseType: TEXT
297297
body: "{data: 'test-request'}"
298298
urlParams: [{key: "query", value: "foo"}]
299299
headers: [{key: "X-Request-Header", value: "req-foo"}]

packages/js/plugins/http/src/__tests__/unit/index.test.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { HttpPlugin } from "../../index";
22

33
import axios, { AxiosResponse, AxiosRequestConfig } from "axios";
4-
import { ResponseType } from "../../types";
54

65
// mock axios
76
jest.mock("axios");
@@ -36,7 +35,7 @@ describe("test http plugin", () => {
3635
{ key: "X-Test-Header", value: "test-header-value" },
3736
],
3837
urlParams: [{ key: "q", value: "test-param" }],
39-
responseType: ResponseType.TEXT,
38+
responseType: "TEXT",
4039
});
4140

4241
expect(mockedAxios.get).lastCalledWith("/api/test", {
@@ -73,7 +72,7 @@ describe("test http plugin", () => {
7372
{ key: "X-Test-Header", value: "test-header-value" },
7473
],
7574
urlParams: [{ key: "q", value: "test-param" }],
76-
responseType: ResponseType.BINARY,
75+
responseType: "BINARY",
7776
});
7877

7978
expect(mockedAxios.get).lastCalledWith("/api/test", {
@@ -115,7 +114,7 @@ describe("test http plugin", () => {
115114
],
116115
urlParams: [{ key: "q", value: "test-param" }],
117116
body: "{request: 1001}",
118-
responseType: ResponseType.TEXT,
117+
responseType: "TEXT",
119118
});
120119

121120
expect(mockedAxios.post).lastCalledWith("/api/test", "{request: 1001}", {
@@ -153,7 +152,7 @@ describe("test http plugin", () => {
153152
],
154153
urlParams: [{ key: "q", value: "test-param" }],
155154
body: "{request: 1001}",
156-
responseType: ResponseType.BINARY,
155+
responseType: "BINARY",
157156
});
158157

159158
expect(mockedAxios.post).lastCalledWith("/api/test", "{request: 1001}", {

packages/js/plugins/http/src/__tests__/unit/util.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { fromAxiosResponse, toAxiosRequestConfig } from "../../util";
2-
import { ResponseType } from "../../types";
32

43
describe("converting axios response", () => {
5-
64
test("response type: text", () => {
75
const response = fromAxiosResponse({
86
status: 200,
@@ -47,7 +45,7 @@ describe("creating axios config", () => {
4745
{ key: "Accept", value: "application-json" },
4846
{ key: "X-Header", value: "test-value" },
4947
],
50-
responseType: ResponseType.TEXT,
48+
responseType: "TEXT",
5149
body: "body-content",
5250
});
5351

@@ -62,7 +60,7 @@ describe("creating axios config", () => {
6260
test("with url params", () => {
6361
const config = toAxiosRequestConfig({
6462
urlParams: [{ key: "tag", value: "data" }],
65-
responseType: ResponseType.BINARY,
63+
responseType: "BINARY",
6664
body: "body-content",
6765
});
6866

packages/js/plugins/http/src/types.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@ export class UrlParam {
1111
value: string;
1212
}
1313

14-
export enum ResponseType {
15-
TEXT,
16-
BINARY,
17-
}
14+
export type ResponseType = "TEXT" | "BINARY";
1815

1916
export class Request {
2017
headers?: Header[];

packages/js/plugins/http/src/util.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Request, Response, Header, ResponseType } from "./types";
1+
import { Request, Response, Header } from "./types";
22

33
import { AxiosResponse, AxiosRequestConfig } from "axios";
44

@@ -50,8 +50,7 @@ export function toAxiosRequestConfig(request: Request): AxiosRequestConfig {
5050
}, {});
5151

5252
let config: AxiosRequestConfig = {
53-
responseType:
54-
request.responseType == ResponseType.BINARY ? "arraybuffer" : "text",
53+
responseType: request.responseType == "BINARY" ? "arraybuffer" : "text",
5554
};
5655

5756
if (urlParams) {

0 commit comments

Comments
 (0)