[BUG] MUI Inferencer sets all fields to required
Closed this issue · 1 comments
Describe the bug
We use a graphql setup with an inferencer to generate CRUD screens using Material UI.
When using the inferencer all the form fields get flagged as 'required'. Since we want to automate the project as much as possible, having to manually remove these required flags is very undesired.
Looking at the source code you can find some hardcoded config on the form fields:
https://github.com/refinedev/refine/blob/master/packages/inferencer/src/inferencers/mui/create.tsx#L141
https://github.com/refinedev/refine/blob/master/packages/inferencer/src/inferencers/mui/create.tsx#L232
https://github.com/refinedev/refine/blob/master/packages/inferencer/src/inferencers/mui/edit.tsx#L152
https://github.com/refinedev/refine/blob/master/packages/inferencer/src/inferencers/mui/edit.tsx#L246
https://github.com/refinedev/refine/blob/master/packages/inferencer/src/inferencers/mui/edit.tsx#L287
Steps To Reproduce
Have a resource with some optional fields
Create CRUD screens with the inferencer
Open the Create screen
Save blank form
All fields will be flagged red
Expected behavior
Expecting the 'required' flag to only be added on resource fields of type 'NON_NULL' (or those marked with "!").
Packages
"@refinedev/core": "^4.49.0",
"@refinedev/graphql": "^6.5.0",
"@refinedev/inferencer": "^4.6.0",
"@refinedev/mui": "^5.14.5",
"@refinedev/react-router-v6": "^4.5.7",
Additional Context
No response
Hey @otakueadwine, understood the need here, yet the Inferencer components' outputs are designed to be edited rather than using it as is. We're marking all inferred fields as required to make sure we're not breaking the interacted APIs with corrupted data.
As a workaround, you can create your own inferencer components, we're exporting all the required methods and components within our @refinedev/inferencer
package and you can copy-paste the source code to implement your own templates.
Unfortunately for now we're not planning changing this behavior of Inferencer components. Let us know if we can help with any other issues 🙏