How can I check the variables from frontend before update record #9109
Replies: 3 comments
-
There's a few ways to address this. If you want to force the update to always require a certain key, for example an id, you can rewrite your query to require that id as a primitive value. Alternatively, you can perform a check on the value of the function isEmptyObject(obj) {
// because Object.keys(new Date()).length === 0;
// we have to do some additional check
return obj // 👈 null and undefined check
&& Object.keys(obj).length === 0
&& Object.getPrototypeOf(obj) === Object.prototype
}
const nonEmptyWhere = { prop: 'value' }
if (isEmptyObject(nonEmptyWhere)) {
// will not log since nonEmptyWhere is not empty
console.log('this won't log')
}
const emptyWhere = {}
if (isEmptyObject(emptyWhere)) {
// will log since emptyWhere is empty
console.log('this will log')
} |
Beta Was this translation helpful? Give feedback.
-
Yes, this can prevent it. but did not resolve completely. |
Beta Was this translation helpful? Give feedback.
-
Right, that's a different question, you specifically asked about restricting from the front end. There's a few ways to make things safer from the backend.
|
Beta Was this translation helpful? Give feedback.
-
Version Information
Server Version:V2.80
CLI Version (for CLI related issue):
What is the current behaviour?
When I update a table , If I did not set where conditions because of forget or a bug .It will update all record. That is not I want and it is risk.
How can I check the variables from frontend before update record. If where condition is empty ,I want to stop this update behave. Can I do some check before update table from backend config by hasura-engine
Beta Was this translation helpful? Give feedback.
All reactions