Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add prevent validateResponseFormat() from validating custom routes #8159

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/ra-core/src/dataProvider/dataFetchActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ export const fetchActionsWithArrayOfRecordsResponse = [
];
export const fetchActionsWithTotalResponse = ['getList', 'getManyReference'];

export const fetchActions = [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd name it reactAdminFetchActions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 448a8ec

...fetchActionsWithRecordResponse,
...fetchActionsWithArrayOfRecordsResponse,
];

export const sanitizeFetchType = (fetchType: string) => {
switch (fetchType) {
case GET_LIST:
Expand Down
6 changes: 5 additions & 1 deletion packages/ra-core/src/dataProvider/useDataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { defaultDataProvider } from './defaultDataProvider';
import validateResponseFormat from './validateResponseFormat';
import { DataProvider } from '../types';
import useLogoutIfAccessDenied from '../auth/useLogoutIfAccessDenied';
import { fetchActions } from './dataFetchActions';

/**
* Hook for getting a dataProvider
Expand Down Expand Up @@ -98,7 +99,10 @@ export const useDataProvider = <
return dataProvider[type]
.apply(dataProvider, args)
.then(response => {
if (process.env.NODE_ENV !== 'production') {
if (
process.env.NODE_ENV !== 'production' &&
fetchActions.includes(type)
) {
validateResponseFormat(response, type);
}
return response;
Expand Down