refine icon indicating copy to clipboard operation
refine copied to clipboard

[BUG] - Using Supabase data provider, the onMutationSuccess callback from useForm doesn't return data

Open jibize opened this issue 1 year ago • 8 comments

Describe the bug

Using the Supabase data provider, in useForm() the onMutationSuccess callback doesn't return any data.

Steps To Reproduce

  1. go to this condesandbox taken from the Supabase codesandbox example
  2. 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.

jibize avatar Feb 25 '24 13:02 jibize

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>
  );
}`

zelbazk avatar Feb 25 '24 16:02 zelbazk

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

image

alicanerdurmaz avatar Feb 26 '24 06:02 alicanerdurmaz

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?

zelbazk avatar Feb 26 '24 12:02 zelbazk

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.

alicanerdurmaz avatar Feb 26 '24 14:02 alicanerdurmaz

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: "*",
        },
    });

alicanerdurmaz avatar Feb 27 '24 08:02 alicanerdurmaz

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 avatar Feb 27 '24 12:02 jibize

@jibize I believe select("*") should be the default, thanks for the PR 🙌

alicanerdurmaz avatar Feb 27 '24 13:02 alicanerdurmaz

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.

issa012 avatar Mar 28 '24 12:03 issa012