| 33 | |
| 34 | // Query collections automatically refetch after handler completes |
| 35 | const configMutationFn = async ({ |
| 36 | transaction, |
| 37 | }: { |
| 38 | transaction: Transaction |
| 39 | }) => { |
| 40 | // Handle inserts |
| 41 | const inserts = transaction.mutations.filter((m) => m.type === `insert`) |
| 42 | await Promise.all( |
| 43 | inserts.map(async (mutation) => { |
| 44 | await api.config.create(mutation.modified) |
| 45 | }), |
| 46 | ) |
| 47 | |
| 48 | // Handle updates |
| 49 | const updates = transaction.mutations.filter((m) => m.type === `update`) |
| 50 | await Promise.all( |
| 51 | updates.map(async (mutation) => { |
| 52 | if (!(`id` in mutation.original)) { |
| 53 | throw new Error(`Original config not found for update`) |
| 54 | } |
| 55 | await api.config.update(mutation.original.id, mutation.changes) |
| 56 | }), |
| 57 | ) |
| 58 | |
| 59 | // Trigger refetch to get confirmed server state |
| 60 | await queryConfigCollection.utils.refetch() |
| 61 | } |
| 62 | |
| 63 | return ( |
| 64 | <TodoApp |