Skip to content

Commit 52b31a3

Browse files
fix(kleros-sdk): replace-graphql-request-library-with-native-fetch
1 parent 56853b9 commit 52b31a3

File tree

6 files changed

+43
-12
lines changed

6 files changed

+43
-12
lines changed

kleros-sdk/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
},
4444
"dependencies": {
4545
"@reality.eth/reality-eth-lib": "^3.2.30",
46-
"graphql-request": "^7.1.0",
4746
"mustache": "^4.2.0",
4847
"viem": "^2.21.26",
4948
"zod": "^3.22.4"

kleros-sdk/src/dataMappings/actions/fetchIpfsJsonAction.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export const fetchIpfsJsonAction = async (mapping: FetchIpfsJsonMapping) => {
3333
throw new RequestError("Fetched data is not JSON", httpUri);
3434
}
3535

36-
const data = await response.json();
36+
const data = (await response.json()) as any;
3737

3838
return createResultObject(data, seek, populate);
3939
};

kleros-sdk/src/dataMappings/actions/subgraphAction.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const subgraphAction = async (mapping: SubgraphMapping) => {
1313
body: JSON.stringify({ query, variables }),
1414
});
1515

16-
const { data } = await response.json();
16+
const { data } = (await response.json()) as any;
1717

1818
return createResultObject(data, seek, populate);
1919
};

kleros-sdk/src/requests/fetchDisputeDetails.ts

+20-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { request, gql } from "graphql-request";
21
import { RequestError } from "../errors";
32

43
type DisputeDetailsQueryResponse = {
@@ -12,8 +11,8 @@ type DisputeDetailsQueryResponse = {
1211
};
1312
};
1413

15-
const fetchDisputeDetails = async (endpoint: string, id: bigint) => {
16-
const query = gql`
14+
const fetchDisputeDetails = async (endpoint: string, id: bigint): Promise<DisputeDetailsQueryResponse> => {
15+
const query = `
1716
query DisputeDetails($id: ID!) {
1817
dispute(id: $id) {
1918
arbitrated {
@@ -28,7 +27,24 @@ const fetchDisputeDetails = async (endpoint: string, id: bigint) => {
2827
const variables = { id: id.toString() };
2928

3029
try {
31-
return await request<DisputeDetailsQueryResponse>(endpoint, query, variables);
30+
const response = await fetch(endpoint, {
31+
method: "POST",
32+
headers: {
33+
"Content-Type": "application/json",
34+
},
35+
body: JSON.stringify({ query, variables }),
36+
});
37+
38+
if (!response.ok) {
39+
const errorData = (await response.json()) as any;
40+
throw new RequestError(
41+
`Error querying Dispute Details: ${errorData?.errors?.[0]?.message || "Unknown error"}`,
42+
endpoint
43+
);
44+
}
45+
46+
const json = (await response.json()) as { data: DisputeDetailsQueryResponse };
47+
return json.data;
3248
} catch (error: any) {
3349
if (error instanceof Error) {
3450
throw new RequestError(`Error querying Dispute Details: ${error.message}`, endpoint);

kleros-sdk/src/requests/fetchDisputeTemplateFromId.ts

+21-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { request, gql } from "graphql-request";
21
import { RequestError } from "../errors";
32

43
type DisputeTemplateQueryResponse = {
@@ -8,8 +7,8 @@ type DisputeTemplateQueryResponse = {
87
};
98
};
109

11-
const fetchDisputeTemplateFromId = async (endpoint: string, id: number) => {
12-
const query = gql`
10+
const fetchDisputeTemplateFromId = async (endpoint: string, id: number): Promise<DisputeTemplateQueryResponse> => {
11+
const query = `
1312
query DisputeTemplate($id: ID!) {
1413
disputeTemplate(id: $id) {
1514
templateData
@@ -19,8 +18,26 @@ const fetchDisputeTemplateFromId = async (endpoint: string, id: number) => {
1918
`;
2019

2120
const variables = { id: id.toString() };
21+
2222
try {
23-
return await request<DisputeTemplateQueryResponse>(endpoint, query, variables);
23+
const response = await fetch(endpoint, {
24+
method: "POST",
25+
headers: {
26+
"Content-Type": "application/json",
27+
},
28+
body: JSON.stringify({ query, variables }),
29+
});
30+
31+
if (!response.ok) {
32+
const errorData = (await response.json()) as any;
33+
throw new RequestError(
34+
`Error querying Dispute Template: ${errorData?.errors?.[0]?.message || "Unknown error"}`,
35+
endpoint
36+
);
37+
}
38+
39+
const json = (await response.json()) as { data: DisputeTemplateQueryResponse };
40+
return json.data;
2441
} catch (error: any) {
2542
if (error instanceof Error) {
2643
throw new RequestError(`Error querying Dispute Template: ${error.message}`, endpoint);

yarn.lock

-1
Original file line numberDiff line numberDiff line change
@@ -7902,7 +7902,6 @@ __metadata:
79027902
"@reality.eth/reality-eth-lib": "npm:^3.2.30"
79037903
"@types/mustache": "npm:^4.2.5"
79047904
"@vitest/ui": "npm:^1.1.3"
7905-
graphql-request: "npm:^7.1.0"
79067905
mocha: "npm:^10.2.0"
79077906
mustache: "npm:^4.2.0"
79087907
rimraf: "npm:^6.0.1"

0 commit comments

Comments
 (0)