Skip to content

Commit

Permalink
0.0.1-alpha6
Browse files Browse the repository at this point in the history
  • Loading branch information
Julio García committed Aug 10, 2021
1 parent 7e12b1f commit 2a22e0e
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ableco/abledev-react",
"version": "0.0.1-alpha5",
"version": "0.0.1-alpha6",
"description": "",
"main": "dist/abledev-react.js",
"types": "dist/index.d.ts",
Expand Down
7 changes: 4 additions & 3 deletions src/useMutation.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { rest } from "msw";
import { useUnsweetenedMutation } from "./useMutation";
import { useUnsweetenedQuery } from "./useQuery";
import useQueryClient from "./useQueryClient";
import superjson from "superjson";

let serverData: { numbers: Array<number> } = {
numbers: [],
Expand All @@ -21,14 +22,14 @@ const server = setupServer(
}

if (key === "mutations/push") {
const newNumber = (req.body as any).number as number;
const newNumber = (req.body as any).json.number as number;
serverData.numbers.push(newNumber);
}

return res(ctx.json({}));
return res(ctx.text(superjson.stringify({})));
}),
rest.get("/abledev/call-query", (_req, res, ctx) => {
return res(ctx.json(serverData.numbers));
return res(ctx.text(superjson.stringify(serverData.numbers)));
}),
);

Expand Down
5 changes: 3 additions & 2 deletions src/useMutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ function useUnsweetenedMutation<ResultType, ArgumentsType>(
},
body: superjson.stringify(mutationArguments),
});
const responseData = await response.json();
return responseData as unknown as ResultType;
const responseText = await response.text();
const responseData = superjson.parse(responseText);
return responseData as ResultType;
} catch (error) {
throw error;
}
Expand Down
3 changes: 2 additions & 1 deletion src/useQuery.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import { useUnsweetenedQuery } from "./useQuery";
import wrapRootComponent from "./wrapRootComponent";
import { setupServer } from "msw/node";
import { rest } from "msw";
import superjson from "superjson";

const server = setupServer(
rest.get("/abledev/call-query", (req, res, ctx) => {
const response: any = { key: req.url.searchParams.get("key") };
if (req.url.searchParams.get("name")) {
response.name = req.url.searchParams.get("name");
}
return res(ctx.json(response));
return res(ctx.text(superjson.stringify(response)));
}),
);

Expand Down
1 change: 1 addition & 0 deletions src/useQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ function useUnsweetenedQuery<ResultType>(
"Content-Type": "application/json",
},
});

const responseText = await response.text();
const responseData = superjson.parse(responseText);
return responseData as ResultType;
Expand Down

0 comments on commit 2a22e0e

Please sign in to comment.