Skip to content

Commit f36f0a6

Browse files
fix(rest): getMany return format (#7049)
1 parent 873c1d8 commit f36f0a6

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

.changeset/witty-dingos-wash.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@refinedev/rest": patch
3+
---
4+
5+
fix: `getMany` method now returns the complete response body
6+
7+
Previously, `getMany` method was returning `body.records` which assumed a specific response structure. Now it returns the complete response body directly, providing more flexibility for different API response formats.

packages/rest/src/create-data-provider.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type {
44
CustomResponse,
55
DataProvider,
66
DeleteOneResponse,
7+
GetManyResponse,
78
GetOneResponse,
89
UpdateManyResponse,
910
UpdateResponse,
@@ -81,7 +82,7 @@ export const createDataProvider = (
8182

8283
return { data };
8384
},
84-
async getMany(params) {
85+
async getMany(params): Promise<GetManyResponse<any>> {
8586
const endpoint = options.getMany.getEndpoint(params);
8687

8788
const headers = await options.getMany.buildHeaders(params);

packages/rest/src/default.options.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type {
77
UpdateParams,
88
HttpError,
99
GetManyParams,
10+
UpdateManyParams,
1011
} from "@refinedev/core";
1112
import type { KyResponse } from "ky";
1213

@@ -78,10 +79,13 @@ export const defaultCreateDataProviderOptions = {
7879

7980
return params.meta?.query ?? queryParams;
8081
},
81-
async mapResponse(response: KyResponse<AnyObject>, _params: GetManyParams) {
82+
async mapResponse(
83+
response: KyResponse<AnyObject[]>,
84+
_params: GetManyParams,
85+
): Promise<AnyObject[]> {
8286
const body = await response.json();
8387

84-
return body.records;
88+
return body;
8589
},
8690
},
8791
create: {

packages/rest/test/methods/getMany.spec.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
import nock from "nock";
22
import { API_URL, createDataProvider } from "..";
33

4-
const response = {
5-
records: [{ id: 1 }, { id: 2 }],
6-
totalCount: 1,
7-
};
8-
4+
const response = [{ id: 1 }, { id: 2 }];
95
const queryParams = { ids: "1,2" };
106

117
nock(API_URL)
@@ -33,6 +29,6 @@ describe("getMany", () => {
3329
},
3430
});
3531

36-
expect(result).toEqual({ data: response.records });
32+
expect(result).toEqual({ data: response });
3733
});
3834
});

0 commit comments

Comments
 (0)