File tree Expand file tree Collapse file tree 6 files changed +153
-132
lines changed
packages/ra-core/src/dataProvider Expand file tree Collapse file tree 6 files changed +153
-132
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import type {
1212 Identifier ,
1313 DataProvider ,
1414 MutationMode ,
15+ CreateResult ,
1516} from '../types' ;
1617import { useEvent } from '../util' ;
1718import {
@@ -96,17 +97,15 @@ export const useCreate = <
9697 } = options ;
9798
9899 const dataProviderCreate = useEvent ( ( resource : string , params ) =>
99- dataProvider
100- . create <
101- RecordType ,
102- ResultRecordType
103- > ( resource , params as CreateParams < RecordType > )
104- . then ( ( { data } ) => data )
100+ dataProvider . create < RecordType , ResultRecordType > (
101+ resource ,
102+ params as CreateParams < RecordType >
103+ )
105104 ) ;
106105
107106 const [ mutate , mutationResult ] = useMutationWithMutationMode <
108107 MutationError ,
109- ResultRecordType ,
108+ CreateResult < ResultRecordType > ,
110109 UseCreateMutateParams < RecordType >
111110 > (
112111 { resource, ...params } ,
@@ -135,7 +134,9 @@ export const useCreate = <
135134 ? result ?. id
136135 : params . data ?. id ;
137136 if ( ! id ) {
138- return undefined ;
137+ throw new Error (
138+ 'Invalid dataProvider response for create: missing id'
139+ ) ;
139140 }
140141 // hack: only way to tell react-query not to fetch this query for the next 5 seconds
141142 // because setQueryData doesn't accept a stale time option
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ import type {
1414 MutationMode ,
1515 GetListResult as OriginalGetListResult ,
1616 GetInfiniteListResult ,
17+ DeleteResult ,
1718} from '../types' ;
1819import {
1920 type Snapshot ,
@@ -93,7 +94,7 @@ export const useDelete = <
9394
9495 const [ mutate , mutationResult ] = useMutationWithMutationMode <
9596 MutationError ,
96- RecordType | undefined ,
97+ DeleteResult < RecordType > ,
9798 UseDeleteMutateParams < RecordType >
9899 > (
99100 { resource, ...params } ,
@@ -110,12 +111,10 @@ export const useDelete = <
110111 'useDelete mutation requires a non-empty id'
111112 ) ;
112113 }
113- return dataProvider
114- . delete < RecordType > (
115- resource ,
116- params as DeleteParams < RecordType >
117- )
118- . then ( ( { data } ) => data ) ;
114+ return dataProvider . delete < RecordType > (
115+ resource ,
116+ params as DeleteParams < RecordType >
117+ ) ;
119118 } ,
120119 updateCache : ( { resource, ...params } , { mutationMode } ) => {
121120 // hack: only way to tell react-query not to fetch this query for the next 5 seconds
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ import type {
1414 MutationMode ,
1515 GetListResult as OriginalGetListResult ,
1616 GetInfiniteListResult ,
17+ DeleteManyResult ,
1718} from '../types' ;
1819import { useEvent } from '../util' ;
1920import {
@@ -93,7 +94,7 @@ export const useDeleteMany = <
9394
9495 const [ mutate , mutationResult ] = useMutationWithMutationMode <
9596 MutationError ,
96- Array < RecordType [ 'id' ] > | undefined ,
97+ DeleteManyResult < RecordType > ,
9798 UseDeleteManyMutateParams < RecordType >
9899 > (
99100 { resource, ...params } ,
@@ -112,12 +113,10 @@ export const useDeleteMany = <
112113 'useDeleteMany mutation requires an array of ids'
113114 ) ;
114115 }
115- return dataProvider
116- . deleteMany < RecordType > (
117- resource ,
118- params as DeleteManyParams < RecordType >
119- )
120- . then ( ( { data } ) => data ) ;
116+ return dataProvider . deleteMany < RecordType > (
117+ resource ,
118+ params as DeleteManyParams < RecordType >
119+ ) ;
121120 } ,
122121 updateCache : ( { resource, ...params } , { mutationMode } ) => {
123122 // hack: only way to tell react-query not to fetch this query for the next 5 seconds
You can’t perform that action at this time.
0 commit comments