MrHertal/react-admin-amplify

Update is trying to set properties it shouldn't (can't)

BruceWheaton opened this issue · 8 comments

I have a number of @connection items in the graphql and they are obviously getting into the data (which is fine). However, when I edit a record, it seems to be trying to set all the properties, not just the changed ones, or even editable ones.

I guess the easy fix is to only update the properties that were specified in the edit view if we can't tell what changed?

Bruce

I just confirmed this by tweaking the demo - can share diffs if needed, but I added an 'address' field to warehouses, and put in edit functionality. When you try to commit the edit there's the same error
message: "The variables input contains a field name 'employees' that is not defined for input object type 'UpdateWarehouseInput' "

Hi,

yes the data provider will update all properties by default, but you can transform data with react-admin before form submission:

const editTransform = ({
  fieldToRemove,
  ...data
}) => ({
  ...data,
});

export const TestEdit = (props) => (
  <Edit {...props} transform={editTransform}>
    <SimpleForm>
      {#...#}
    </SimpleForm>
  </Edit>
);

Does that code work for you? I tried a more explicit approach, but it Edit didn't seem to use the transform function.
const editTransform = (data) => ({ id: data.id, emailAddress: data.emailAddress, blocked: data.blocked, name: data.name, source: data.source, note: data.note });
Used:
<Edit {...props} transform={editTransform}>

It should work, here is the documentation: https://marmelab.com/react-admin/CreateEdit.html#transform

Should work, doesn't seem to. I tested on react-admin and filed an issue. Thankshttps://codesandbox.io/s/keen-beaver-z8me5?file=/src/posts/PostEdit.tsx

Did some more testing and was able to get react-admin to accept changes - it's very fussy on that function.
Following that, I can see my transform changes working on the optimistically set view, but 5 seconds later the actual update fails with the original error, indicating that the update had all the variables.
Are there two updates happening? Or is the update using the untransformed data?
Oh - even deleteUser is having the issue. Only the ID should be going to a delete.

Transform is working for me now. User error? Maybe a malformed transform function?
BTW - I sent you an email. Thanks for your help. You can resolve this, but I think a short term solution would be adding the transform to the docs because it is needed to update anything with any connections (the main point of graphql). An example also - there's no feedback for malformed transforms.

Glad you could solve this.