graphqlhasura

Graphql query to update a table in hasura


I am trying to update a table in hasura. I have written the below query to update a row in users table where id(primary key) is equal to the passed id from the variable. If the id matches then update the field account_id which is nullable and unique inside hasura.

const query = `mutation updateAccountId($id: String!, $account_id: String) {
  update_users(where: {id: {_eq: $id}}, _set: {account_id: $account_id}){
    affected_rows
  }
}`;

fetch("https://xyz.hasura.app/v1/graphql", {
  method: "post",
  headers: {
    "content-type": "application/json",
    Authorization: `Bearer ${token}`,
  },
  body: JSON.stringify({
    query,
    variables: {
      id: "P9gc6WanL9YAy7JdD6pEbcfULYt2",
      account_id: "3afc4fds2ds4",
    },
  }),
}).then((response) => {
  console.log(
    response,
  );
});

I'm getting the below error after trying a few times. Don't know if this is a graphql syntax error or something related to hasura.

{
    "errors": [
        {
            "extensions": {
                "code": "validation-failed",
                "path": "$.selectionSet.update_users"
            },
            "message": "'update_users' has no argument named '_set'"
        }
    ]
}

Solution

  • Solved. The problem was I didn't enable the permission to update the users table inside hasura that's why I was getting that error.