Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Using GraphQL as the data provider, Refines hooks like useUpdate, onMutationSuccess, onSuccess, etc return undefined data #6600

Open
maximdolphin opened this issue Dec 21, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@maximdolphin
Copy link

Describe the bug

I am trying to make a form submission with Refine, and for some reason anytime I try to receive the data from the mutation, it returns it as undefined but says the mutation was successful. Here's what my backend returns for instance:
{
"id": 37,
"title": "schedule",
"semesterId": "Spring 2025",
"entries": []
}

Steps To Reproduce

    const {formProps, modalProps, close, mutationResult} = useModalForm({
            action: "create",
            defaultVisible: true,
            meta: {
                select: "*",
                gqlMutation: CREATE_CLASS_SCHEDULE_MUTATION,
            },
        onMutationSuccess: (response) => {
            console.log('Full response:', response);
            const createdSchedule = response?.data?.createClassSchedule;
            if (createdSchedule) {
                console.log('Created schedule:', createdSchedule);
                onFinish(createdSchedule as ClassSchedule);
                close();
                onClose();
            } else {
                console.error('Created schedule data is missing from the response');
            }
        },
            onMutationError: () => {
                throw new Error("Failed to create schedule");
            },
        }
    );

Expected behavior

The data should've returned in that aforementioned style, but yet it keeps returning data undefined and context undefined

Packages

Additional Context

No response

@maximdolphin maximdolphin added the bug Something isn't working label Dec 21, 2024
@alicanerdurmaz
Copy link
Member

Hello @maximdolphin, thanks for the issue.

By default, @refinedev/graphql gets data from a response like this:

const key = `updateOne${camelcase(singular(params.resource), {
       pascalCase: true,
})}`;

return response.data?.[key]

If your backend returns a different format, you need to give your dataMapper to get your data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants