Skip to content

Commit

Permalink
Merge pull request #381 from psteinroe/fix/return-input-from-mutations
Browse files Browse the repository at this point in the history
fix/return input from mutations
  • Loading branch information
psteinroe committed Feb 14, 2024
2 parents 987c7fe + 1a011d7 commit 099eff9
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/strong-sheep-laugh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@supabase-cache-helpers/postgrest-core": patch
---

fix: return input from mutations without query so that cache updates still work
9 changes: 8 additions & 1 deletion packages/postgrest-core/__tests__/insert-fetcher.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,14 @@ describe('insert', () => {
{ username: `${testRunPrefix}-username-1` },
{ username: `${testRunPrefix}-username-2` },
]),
).resolves.toEqual(null);
).resolves.toEqual([
{
normalizedData: { username: `${testRunPrefix}-username-1` },
},
{
normalizedData: { username: `${testRunPrefix}-username-2` },
},
]);
});

it('should support passing a query', async () => {
Expand Down
7 changes: 6 additions & 1 deletion packages/postgrest-core/__tests__/update-fetcher.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ describe('update', () => {
id: contact?.id,
username: `${testRunPrefix}-username-2`,
});
expect(updatedContact).toEqual(null);
expect(updatedContact).toEqual({
normalizedData: {
id: expect.anything(),
username: `${testRunPrefix}-username-2`,
},
});
const { data } = await client
.from('contact')
.select('*')
Expand Down
9 changes: 8 additions & 1 deletion packages/postgrest-core/__tests__/upsert-fetcher.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,14 @@ describe('upsert', () => {
{ username: `${testRunPrefix}-username-2` },
],
),
).resolves.toEqual(null);
).resolves.toEqual([
{
normalizedData: { username: `${testRunPrefix}-username-1` },
},
{
normalizedData: { username: `${testRunPrefix}-username-2` },
},
]);
});

it('should support passing a query', async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/postgrest-core/src/insert-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function buildInsertFetcher<
);
}
await qb.insert(input as any).throwOnError();
return null;
return input.map((d) => ({ normalizedData: d as R }));
};
}

Expand Down
2 changes: 1 addition & 1 deletion packages/postgrest-core/src/update-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,5 @@ export const buildUpdateFetcher =
return buildMutationFetcherResponse(data as R, { userQueryPaths, paths });
}
await filterBuilder.throwOnError().single();
return null;
return { normalizedData: input as R };
};
4 changes: 3 additions & 1 deletion packages/postgrest-core/src/upsert-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,7 @@ export const buildUpsertFetcher =
await qb
.upsert(input as any) // todo fix type
.throwOnError();
return null;
return input.map((d) => ({
normalizedData: d as R,
}));
};
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ describe('useUpdateMutation', () => {
const { trigger: update } = useUpdateMutation(
client.from('contact'),
['id'],
'id',
null,
{
revalidateTables: [{ schema: 'public', table: 'contact_note' }],
onSuccess: () => setSuccess(true),
Expand Down

0 comments on commit 099eff9

Please sign in to comment.