panter / ra-data-prisma

Packages to connect react-admin with prisma version 2
MIT License
84 stars 28 forks source link

Empty id variable prevent updating #45

Closed yograf closed 3 years ago

yograf commented 3 years ago

When trying to update entity data variable is sent with {id: undefind} inside and prevent updating

macrozone commented 3 years ago

@yograf thank you for your contribution! can you check why the tests fail?

endlessdev commented 3 years ago

I got the same errors.

I solved this problem through custom apollo middleware

const adminMiddleware = new ApolloLink((operation, forward) => {
  if (operation.operationName.includes('admin')) {
    if (JSON.stringify(operation?.variables?.data?.id) === '{}') {
      // eslint-disable-next-line no-param-reassign
      delete operation.variables.data.id;
    }
  }
  return forward(operation);
});
macrozone commented 3 years ago

I got the same errors.

I solved this problem through custom apollo middleware

const adminMiddleware = new ApolloLink((operation, forward) => {
  if (operation.operationName.includes('admin')) {
    if (JSON.stringify(operation?.variables?.data?.id) === '{}') {
      // eslint-disable-next-line no-param-reassign
      delete operation.variables.data.id;
    }
  }
  return forward(operation);
});

thanks for sharing your workaround. Not sure if @yograf could already look into the failing tests.

If they pass, we can merge this