[BUG] - Using Supabase data provider, the onMutationSuccess callback from useForm doesn't return data
Describe the bug
Using the Supabase data provider, in useForm() the onMutationSuccess callback doesn't return any data.
Steps To Reproduce
- go to this condesandbox taken from the Supabase codesandbox example
- edit a blog post and save, look at the console log that prints the variables from the onMutationSuccess callback. data is undefined
Expected behavior
According to the doc, data should hold the result of the mutation.
Packages
- @refine/supabase
Additional Context
The problem seems to be present when creating new record as well. The codesandbox doesn't show this because at the moment we can't create a new record from the Supabase example, see #5678.
Having the same experience.
import { Create, useForm } from "@refinedev/antd";
import { Form, Input } from "antd";
import { useCreate } from "@refinedev/core";
import { ITemplate } from "@utility/interfaces";
export default function BlogPostCreate() {
const { mutate } = useCreate();
const { formProps, saveButtonProps } = useForm({
onMutationSuccess: (data, variables, context, isAutoSave) => {
console.log({ data, variables, context, isAutoSave });
},
});
return (
<Create saveButtonProps={saveButtonProps}>
<Form {...formProps} layout="vertical">
<Form.Item
label={"Title"}
name={["title"]}
rules={[
{
required: true,
},
]}
>
<Input />
</Form.Item>
</Form>
</Create>
);
}`
Hello @jbeaudlet @zelbazk,
What is the response in your tests? In my tests, response is empty so because of that onMutationSuccess data is undefined
Request URL: https://iwdfzvfqbtokqetmbmbp.supabase.co/rest/v1/blog_posts?id=eq.000e3b65-43f5-4b0d-891b-ad73df4033e8 Request Method: PATCH Status Code: 204 No Content
Hi @alicanerdurmaz Thanks for pointing this out. it's the same for me. Do you know why the response is empty and not returning anything? I am using the refine/supabase data provider, is there a setting I am missing?
Hi @alicanerdurmaz Thanks for pointing this out. it's the same for me. Do you know why the response is empty and not returning anything? I am using the refine/supabase data provider, is there a setting I am missing?
Supabase client from @supabase/supabase-js returns undefined, I will debug when I find time.
Hello again @jibize @zelbazk,
for supabase to return data, we need to specify the fields we want. you can use like this
const { formProps, saveButtonProps } = useForm({
meta: {
select: "*",
},
});
Hi @alicanerdurmaz,
Thank you for the tip. Is this the intended behaviour? There is no mention in the doc. Also it looks like when using another data provider we don't need to set the meta select option. Also in Supabase doc, when the data is needed back, select() needs to be set at the end of the query. See my pull request.
@jibize I believe select("*") should be the default, thanks for the PR 🙌
Hi @alicanerdurmaz @BatuhanW I think I know how to fix this issue. First of all, in order to update and return the data, select() should be appended at the end of the query, as per the Supabase docs. However, 1 test, which should return error PGRST106 is failing. I think it it is failing because it doesn't expect the "select" parameter to be in the query, that is why it is throwing ERR_NOCK_NO_MATCH. I added the select parameter, and the test is working correctly. Please, assign this to me so I can submit a PR.