Skip to content

Commit

Permalink
Revert "HTTP plugin upgrade"
Browse files Browse the repository at this point in the history
  • Loading branch information
dOrgJelli authored Mar 10, 2021
1 parent 3dd9364 commit 2428c5d
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 23 deletions.
12 changes: 7 additions & 5 deletions packages/js/plugins/http/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ type Response {
type Request {
headers: [Header!]
urlParams: [UrlParam!]
responseType: ResponseType!
responseType: String! # "TEXT" || "BINARY"
body: String
}

enum ResponseType {
TEXT
BINARY
}
# Enum types curently not supported
#
# enum ResponseType {
# TEXT
# BINARY
# }

type Query {
get(url: String!, request: Request): Response
Expand Down
4 changes: 2 additions & 2 deletions packages/js/plugins/http/src/__tests__/e2e/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ describe("e2e tests for HttpPlugin", () => {
post(
url: "http://www.example.com/api"
request: {
responseType: 1
responseType: BINARY
body: "{data: 'test-request'}"
}
)
Expand Down Expand Up @@ -293,7 +293,7 @@ describe("e2e tests for HttpPlugin", () => {
post(
url: "http://www.example.com/api"
request: {
responseType: 0
responseType: TEXT
body: "{data: 'test-request'}"
urlParams: [{key: "query", value: "foo"}]
headers: [{key: "X-Request-Header", value: "req-foo"}]
Expand Down
9 changes: 4 additions & 5 deletions packages/js/plugins/http/src/__tests__/unit/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { HttpPlugin } from "../../index";

import axios, { AxiosResponse, AxiosRequestConfig } from "axios";
import { ResponseType } from "../../types";

// mock axios
jest.mock("axios");
Expand Down Expand Up @@ -36,7 +35,7 @@ describe("test http plugin", () => {
{ key: "X-Test-Header", value: "test-header-value" },
],
urlParams: [{ key: "q", value: "test-param" }],
responseType: ResponseType.TEXT,
responseType: "TEXT",
});

expect(mockedAxios.get).lastCalledWith("/api/test", {
Expand Down Expand Up @@ -73,7 +72,7 @@ describe("test http plugin", () => {
{ key: "X-Test-Header", value: "test-header-value" },
],
urlParams: [{ key: "q", value: "test-param" }],
responseType: ResponseType.BINARY,
responseType: "BINARY",
});

expect(mockedAxios.get).lastCalledWith("/api/test", {
Expand Down Expand Up @@ -115,7 +114,7 @@ describe("test http plugin", () => {
],
urlParams: [{ key: "q", value: "test-param" }],
body: "{request: 1001}",
responseType: ResponseType.TEXT,
responseType: "TEXT",
});

expect(mockedAxios.post).lastCalledWith("/api/test", "{request: 1001}", {
Expand Down Expand Up @@ -153,7 +152,7 @@ describe("test http plugin", () => {
],
urlParams: [{ key: "q", value: "test-param" }],
body: "{request: 1001}",
responseType: ResponseType.BINARY,
responseType: "BINARY",
});

expect(mockedAxios.post).lastCalledWith("/api/test", "{request: 1001}", {
Expand Down
6 changes: 2 additions & 4 deletions packages/js/plugins/http/src/__tests__/unit/util.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { fromAxiosResponse, toAxiosRequestConfig } from "../../util";
import { ResponseType } from "../../types";

describe("converting axios response", () => {

test("response type: text", () => {
const response = fromAxiosResponse({
status: 200,
Expand Down Expand Up @@ -47,7 +45,7 @@ describe("creating axios config", () => {
{ key: "Accept", value: "application-json" },
{ key: "X-Header", value: "test-value" },
],
responseType: ResponseType.TEXT,
responseType: "TEXT",
body: "body-content",
});

Expand All @@ -62,7 +60,7 @@ describe("creating axios config", () => {
test("with url params", () => {
const config = toAxiosRequestConfig({
urlParams: [{ key: "tag", value: "data" }],
responseType: ResponseType.BINARY,
responseType: "BINARY",
body: "body-content",
});

Expand Down
5 changes: 1 addition & 4 deletions packages/js/plugins/http/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ export class UrlParam {
value: string;
}

export enum ResponseType {
TEXT,
BINARY,
}
export type ResponseType = "TEXT" | "BINARY";

export class Request {
headers?: Header[];
Expand Down
5 changes: 2 additions & 3 deletions packages/js/plugins/http/src/util.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Request, Response, Header, ResponseType } from "./types";
import { Request, Response, Header } from "./types";

import { AxiosResponse, AxiosRequestConfig } from "axios";

Expand Down Expand Up @@ -50,8 +50,7 @@ export function toAxiosRequestConfig(request: Request): AxiosRequestConfig {
}, {});

let config: AxiosRequestConfig = {
responseType:
request.responseType == ResponseType.BINARY ? "arraybuffer" : "text",
responseType: request.responseType == "BINARY" ? "arraybuffer" : "text",
};

if (urlParams) {
Expand Down

0 comments on commit 2428c5d

Please sign in to comment.