Skip to content

Commit 3dd9364

Browse files
authored
Merge pull request #186 from NodeFactoryIo/mmuftic/http-plugin-upgrade
HTTP plugin upgrade
2 parents 6cd18b4 + eeedc61 commit 3dd9364

6 files changed

Lines changed: 23 additions & 18 deletions

File tree

packages/js/plugins/http/schema.graphql

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

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

3230
type Query {
3331
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: BINARY
254+
responseType: 1
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: TEXT
296+
responseType: 0
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: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { HttpPlugin } from "../../index";
22

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

56
// mock axios
67
jest.mock("axios");
@@ -35,7 +36,7 @@ describe("test http plugin", () => {
3536
{ key: "X-Test-Header", value: "test-header-value" },
3637
],
3738
urlParams: [{ key: "q", value: "test-param" }],
38-
responseType: "TEXT",
39+
responseType: ResponseType.TEXT,
3940
});
4041

4142
expect(mockedAxios.get).lastCalledWith("/api/test", {
@@ -72,7 +73,7 @@ describe("test http plugin", () => {
7273
{ key: "X-Test-Header", value: "test-header-value" },
7374
],
7475
urlParams: [{ key: "q", value: "test-param" }],
75-
responseType: "BINARY",
76+
responseType: ResponseType.BINARY,
7677
});
7778

7879
expect(mockedAxios.get).lastCalledWith("/api/test", {
@@ -114,7 +115,7 @@ describe("test http plugin", () => {
114115
],
115116
urlParams: [{ key: "q", value: "test-param" }],
116117
body: "{request: 1001}",
117-
responseType: "TEXT",
118+
responseType: ResponseType.TEXT,
118119
});
119120

120121
expect(mockedAxios.post).lastCalledWith("/api/test", "{request: 1001}", {
@@ -152,7 +153,7 @@ describe("test http plugin", () => {
152153
],
153154
urlParams: [{ key: "q", value: "test-param" }],
154155
body: "{request: 1001}",
155-
responseType: "BINARY",
156+
responseType: ResponseType.BINARY,
156157
});
157158

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

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

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

34
describe("converting axios response", () => {
5+
46
test("response type: text", () => {
57
const response = fromAxiosResponse({
68
status: 200,
@@ -45,7 +47,7 @@ describe("creating axios config", () => {
4547
{ key: "Accept", value: "application-json" },
4648
{ key: "X-Header", value: "test-value" },
4749
],
48-
responseType: "TEXT",
50+
responseType: ResponseType.TEXT,
4951
body: "body-content",
5052
});
5153

@@ -60,7 +62,7 @@ describe("creating axios config", () => {
6062
test("with url params", () => {
6163
const config = toAxiosRequestConfig({
6264
urlParams: [{ key: "tag", value: "data" }],
63-
responseType: "BINARY",
65+
responseType: ResponseType.BINARY,
6466
body: "body-content",
6567
});
6668

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

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

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

1619
export class Request {
1720
headers?: Header[];

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

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

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

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

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

5657
if (urlParams) {

0 commit comments

Comments
 (0)