Skip to content

Commit ba40a8d

Browse files
committed
Don't enable query cancellation in production
1 parent dc2d141 commit ba40a8d

File tree

3 files changed

+262
-282
lines changed

3 files changed

+262
-282
lines changed

packages/ra-data-graphql/src/index.ts

-2
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,6 @@ const buildGraphQLProvider = (options: Options): DataProvider => {
228228
callApollo(UPDATE_MANY, resource, params),
229229
};
230230

231-
raDataProvider.supportAbortSignal = process.env.NODE_ENV === 'production';
232-
233231
return raDataProvider;
234232
};
235233

packages/ra-data-json-server/src/index.ts

+111-118
Original file line numberDiff line numberDiff line change
@@ -33,133 +33,126 @@ import { fetchUtils, DataProvider } from 'ra-core';
3333
*
3434
* export default App;
3535
*/
36-
export default (apiUrl, httpClient = fetchUtils.fetchJson): DataProvider => {
37-
const dataProvider: DataProvider = {
38-
getList: (resource, params) => {
39-
const { page, perPage } = params.pagination;
40-
const { field, order } = params.sort;
41-
const query = {
42-
...fetchUtils.flattenObject(params.filter),
43-
_sort: field,
44-
_order: order,
45-
_start: (page - 1) * perPage,
46-
_end: page * perPage,
47-
};
48-
const url = `${apiUrl}/${resource}?${stringify(query)}`;
36+
export default (apiUrl, httpClient = fetchUtils.fetchJson): DataProvider => ({
37+
getList: (resource, params) => {
38+
const { page, perPage } = params.pagination;
39+
const { field, order } = params.sort;
40+
const query = {
41+
...fetchUtils.flattenObject(params.filter),
42+
_sort: field,
43+
_order: order,
44+
_start: (page - 1) * perPage,
45+
_end: page * perPage,
46+
};
47+
const url = `${apiUrl}/${resource}?${stringify(query)}`;
4948

50-
return httpClient(url, { signal: params?.signal }).then(
51-
({ headers, json }) => {
52-
if (!headers.has('x-total-count')) {
53-
throw new Error(
54-
'The X-Total-Count header is missing in the HTTP Response. The jsonServer Data Provider expects responses for lists of resources to contain this header with the total number of results to build the pagination. If you are using CORS, did you declare X-Total-Count in the Access-Control-Expose-Headers header?'
55-
);
56-
}
57-
return {
58-
data: json,
59-
total: parseInt(
60-
headers.get('x-total-count').split('/').pop(),
61-
10
62-
),
63-
};
49+
return httpClient(url, { signal: params?.signal }).then(
50+
({ headers, json }) => {
51+
if (!headers.has('x-total-count')) {
52+
throw new Error(
53+
'The X-Total-Count header is missing in the HTTP Response. The jsonServer Data Provider expects responses for lists of resources to contain this header with the total number of results to build the pagination. If you are using CORS, did you declare X-Total-Count in the Access-Control-Expose-Headers header?'
54+
);
6455
}
65-
);
66-
},
56+
return {
57+
data: json,
58+
total: parseInt(
59+
headers.get('x-total-count').split('/').pop(),
60+
10
61+
),
62+
};
63+
}
64+
);
65+
},
6766

68-
getOne: (resource, params) =>
69-
httpClient(`${apiUrl}/${resource}/${params.id}`, {
70-
signal: params?.signal,
71-
}).then(({ json }) => ({
72-
data: json,
73-
})),
67+
getOne: (resource, params) =>
68+
httpClient(`${apiUrl}/${resource}/${params.id}`, {
69+
signal: params?.signal,
70+
}).then(({ json }) => ({
71+
data: json,
72+
})),
7473

75-
getMany: (resource, params) => {
76-
const query = {
77-
id: params.ids,
78-
};
79-
const url = `${apiUrl}/${resource}?${stringify(query)}`;
80-
return httpClient(url, { signal: params?.signal }).then(
81-
({ json }) => ({
82-
data: json,
83-
})
84-
);
85-
},
74+
getMany: (resource, params) => {
75+
const query = {
76+
id: params.ids,
77+
};
78+
const url = `${apiUrl}/${resource}?${stringify(query)}`;
79+
return httpClient(url, { signal: params?.signal }).then(({ json }) => ({
80+
data: json,
81+
}));
82+
},
8683

87-
getManyReference: (resource, params) => {
88-
const { page, perPage } = params.pagination;
89-
const { field, order } = params.sort;
90-
const query = {
91-
...fetchUtils.flattenObject(params.filter),
92-
[params.target]: params.id,
93-
_sort: field,
94-
_order: order,
95-
_start: (page - 1) * perPage,
96-
_end: page * perPage,
97-
};
98-
const url = `${apiUrl}/${resource}?${stringify(query)}`;
84+
getManyReference: (resource, params) => {
85+
const { page, perPage } = params.pagination;
86+
const { field, order } = params.sort;
87+
const query = {
88+
...fetchUtils.flattenObject(params.filter),
89+
[params.target]: params.id,
90+
_sort: field,
91+
_order: order,
92+
_start: (page - 1) * perPage,
93+
_end: page * perPage,
94+
};
95+
const url = `${apiUrl}/${resource}?${stringify(query)}`;
9996

100-
return httpClient(url, { signal: params?.signal }).then(
101-
({ headers, json }) => {
102-
if (!headers.has('x-total-count')) {
103-
throw new Error(
104-
'The X-Total-Count header is missing in the HTTP Response. The jsonServer Data Provider expects responses for lists of resources to contain this header with the total number of results to build the pagination. If you are using CORS, did you declare X-Total-Count in the Access-Control-Expose-Headers header?'
105-
);
106-
}
107-
return {
108-
data: json,
109-
total: parseInt(
110-
headers.get('x-total-count').split('/').pop(),
111-
10
112-
),
113-
};
97+
return httpClient(url, { signal: params?.signal }).then(
98+
({ headers, json }) => {
99+
if (!headers.has('x-total-count')) {
100+
throw new Error(
101+
'The X-Total-Count header is missing in the HTTP Response. The jsonServer Data Provider expects responses for lists of resources to contain this header with the total number of results to build the pagination. If you are using CORS, did you declare X-Total-Count in the Access-Control-Expose-Headers header?'
102+
);
114103
}
115-
);
116-
},
117-
118-
update: (resource, params) =>
119-
httpClient(`${apiUrl}/${resource}/${params.id}`, {
120-
method: 'PUT',
121-
body: JSON.stringify(params.data),
122-
}).then(({ json }) => ({ data: json })),
104+
return {
105+
data: json,
106+
total: parseInt(
107+
headers.get('x-total-count').split('/').pop(),
108+
10
109+
),
110+
};
111+
}
112+
);
113+
},
123114

124-
// json-server doesn't handle filters on UPDATE route, so we fallback to calling UPDATE n times instead
125-
updateMany: (resource, params) =>
126-
Promise.all(
127-
params.ids.map(id =>
128-
httpClient(`${apiUrl}/${resource}/${id}`, {
129-
method: 'PUT',
130-
body: JSON.stringify(params.data),
131-
})
132-
)
133-
).then(responses => ({
134-
data: responses.map(({ json }) => json.id),
135-
})),
115+
update: (resource, params) =>
116+
httpClient(`${apiUrl}/${resource}/${params.id}`, {
117+
method: 'PUT',
118+
body: JSON.stringify(params.data),
119+
}).then(({ json }) => ({ data: json })),
136120

137-
create: (resource, params) =>
138-
httpClient(`${apiUrl}/${resource}`, {
139-
method: 'POST',
140-
body: JSON.stringify(params.data),
141-
}).then(({ json }) => ({
142-
data: { ...params.data, id: json.id } as any,
143-
})),
121+
// json-server doesn't handle filters on UPDATE route, so we fallback to calling UPDATE n times instead
122+
updateMany: (resource, params) =>
123+
Promise.all(
124+
params.ids.map(id =>
125+
httpClient(`${apiUrl}/${resource}/${id}`, {
126+
method: 'PUT',
127+
body: JSON.stringify(params.data),
128+
})
129+
)
130+
).then(responses => ({
131+
data: responses.map(({ json }) => json.id),
132+
})),
144133

145-
delete: (resource, params) =>
146-
httpClient(`${apiUrl}/${resource}/${params.id}`, {
147-
method: 'DELETE',
148-
}).then(({ json }) => ({ data: json })),
134+
create: (resource, params) =>
135+
httpClient(`${apiUrl}/${resource}`, {
136+
method: 'POST',
137+
body: JSON.stringify(params.data),
138+
}).then(({ json }) => ({
139+
data: { ...params.data, id: json.id } as any,
140+
})),
149141

150-
// json-server doesn't handle filters on DELETE route, so we fallback to calling DELETE n times instead
151-
deleteMany: (resource, params) =>
152-
Promise.all(
153-
params.ids.map(id =>
154-
httpClient(`${apiUrl}/${resource}/${id}`, {
155-
method: 'DELETE',
156-
})
157-
)
158-
).then(responses => ({
159-
data: responses.map(({ json }) => json.id),
160-
})),
161-
};
142+
delete: (resource, params) =>
143+
httpClient(`${apiUrl}/${resource}/${params.id}`, {
144+
method: 'DELETE',
145+
}).then(({ json }) => ({ data: json })),
162146

163-
dataProvider.supportAbortSignal = process.env.NODE_ENV === 'production';
164-
return dataProvider;
165-
};
147+
// json-server doesn't handle filters on DELETE route, so we fallback to calling DELETE n times instead
148+
deleteMany: (resource, params) =>
149+
Promise.all(
150+
params.ids.map(id =>
151+
httpClient(`${apiUrl}/${resource}/${id}`, {
152+
method: 'DELETE',
153+
})
154+
)
155+
).then(responses => ({
156+
data: responses.map(({ json }) => json.id),
157+
})),
158+
});

0 commit comments

Comments
 (0)