-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
React-admin changes the value of a field with typeof value === 'object'. #4277
Comments
Would you mind forking the sandbox and modify it so that we don't have to ? Thanks! |
Hi, @djhi. The fact is that ra-data-graphql-simple changes the input data from the server for the needs of react-admin. However, he does this for all fields, regardless of their context. And it turns out that even if the field does not have __typename (has the graphql data type "SCALAR"), the script processes it the same way as the nested type (potentially Resource). This is definitely not necessary. Unfortunately, making changes to your repository is problematic for me. But I'm asking for help making changes to
This change will solve my problem. But I am concerned about changing data from the server before this data gets into the component. This is a potentially dangerous practice, as I, as a developer, do not expect this behavior. I think that all changes to the source data should occur in the component that uses them. What do you think about this? |
Just putting @wmwart's suggestion here as a diff: // in packages/ra-data-graphql-simple/src/getResponseParser.js
@@ -31,7 +31,7 @@ const sanitizeResource = data => {
dataKey.id && {
[`${key}.id`]: dataKey.id,
}),
- [key]: sanitizeResource(dataKey),
+ [key]: (dataKey.__typename) ? sanitizeResource(dataKey) : dataKey,
};
} @djhi does that make the issue clearer? |
What you were expecting:
Expected to return the value passed from the server.
What happened instead:
Instead, React Admin changes the value that the server passed.
Steps to reproduce:
This issue is a copy of #4037 one since it was not completed and closed.
My server returns a field with a typeof value === 'object'.
The problem appears if there is an array in the returned object. The admin admin changes it, tries to add a parameter with the identifier values (this is not accurate) of the array elements. This is probably somehow related to the preparation of data for arrayInput, however, the value of my field is not a resource, which means that I do not need to change my data.
props.save(finalValues, finalRedirect);
I think this problem is very important. The reliability of transmitted data of any type must remain unchanged. In addition, this prevents you from making your own components for situations more complex than in the documentation.
Environment
The text was updated successfully, but these errors were encountered: