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] GraphQL dataProvider is missing the params.payload variables merged into the buildVariables. #6665

Open
sudeepjd opened this issue Jan 31, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@sudeepjd
Copy link
Contributor

sudeepjd commented Jan 31, 2025

Describe the bug

The payload values from useCustomMutation hook are not being passed to the GraphQL custom dataprovider to be sent onwards to urql. Although the values parameter in the useCustomMutation hook is required, the custom section of the dataprovider does not use this parameter value.

In the graphql/src/dataProvider/options.ts

custom: {
dataMapper: (response: OperationResult<any>, params: CustomParams) =>
response.data ?? response.error?.message,
buildVariables: (params: CustomParams) => ({
...params?.meta?.variables,
...params?.meta?.gqlVariables,
}),

The required payload:values from variables are not being passed in from the useCustomMutation hook.

return custom<TData>({
url,
method,
payload: values,
meta: combinedMeta,
metaData: combinedMeta,
headers: { ...config?.headers },
});

From line 145, where it is being stored in payload.

Steps To Reproduce

Create a new file with the following code

const { mutate } = useCustomMutation();

  const handleCreateCustomData = () => {
    mutate({
      url: API_URL,
      values: { //Although required by TypeScript this does not get passed through.
        val1: "Value",
        val2: "Value2"
      },
      method: "post",
      meta: {
        gqlMutation: <GQL_MUTATION>,
      },
    });
  };

The values are not being passed to the graphQL and it expects gqlVariables populated through meta.

Expected behavior

Add in the line

...(typeof params.payload === "object" ? params.payload : undefined),

into the buildVariables function before line 292 below, as you can see in the code block below it is only taking the meta variables and not the payload from the useCustomMutation hook.

custom: {
dataMapper: (response: OperationResult<any>, params: CustomParams) =>
response.data ?? response.error?.message,
buildVariables: (params: CustomParams) => ({
...params?.meta?.variables,
...params?.meta?.gqlVariables,
}),

Packages

  • @refinedev/core
  • @refinedev/graphql

Additional Context

The same is done on the buildVariables in the update part of the graphql dataprovider, so seems to have been missed out on the useCustomMutation.

buildVariables: (params: UpdateParams<any>) => {
return {
input: {
id: params.id,
update: params.variables,
...params.meta?.gqlVariables,
},

@sudeepjd sudeepjd added the bug Something isn't working label Jan 31, 2025
@yousef-romany
Copy link

Hi @sudeepjd, I think must be

buildVariables: (params: CustomParams) => ({ ...params?.meta?.variables, ...params?.meta?.gqlVariables, ...params?.payload, // Fix: Include the payload (values from useCustomMutation) }),

params.payload will now be correctly passed as part of the GraphQL variables
This aligns with how the update mutation in the same file already includes params.variables.

@sudeepjd
Copy link
Contributor Author

sudeepjd commented Feb 2, 2025

@yousef-romany Yes. That is exactly what I asked for in the Expected behaviour section of the bug I filed, except I put it at the top instead of the bottom. Either will do.

For now we can overide the options.ts, but would be good to have a fix.

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