Hasura Error - GraphQL error: field "user_id" not found in type: 'projects_insert_input'

Viewed 5410

I'm trying to add a new project with a connected user assigned to a project but I continue to receive an error 'GraphQL error: field "user_id" not found in type: 'projects_insert_input''

Each project has a user_id column mandatory (I can add projects inside the graphiql editor on hasura, but not on my client)

mutation

const ADD_PROJECT = gql`
  mutation ($project: String!,  $isPublic: Boolean!, $user: String!) {
  insert_projects(objects: 
    {
        title: $project, 
        is_public: $isPublic,
        user_id: $user
    }
    ) {
    affected_rows
    returning {
      id
      title
      created_at
      is_completed

    }
  }
}
 `;
const ProjectInput = ({ isPublic = false }) => {
    let input;
    const [projectInput, setProjectInput] = useState('');

    const [addProject] = useMutation(ADD_PROJECT);

    return (
        <form className="formInput">
            <input
                className="input"
                placeholder="What needs to be done?"
                value={projectInput}
                onChange={e => (setProjectInput(e.target.value))}
                ref={n => (input = n)}
            />

            <button onClick={(e) => {
                e.preventDefault();
                addProject({
                    variables:
                    {
                        project: projectInput,
                        isPublic,
                        user: "auth0|5e6d66e02ae6a80c8bc42eb4"
                        // description: projectDescInput
                    }
                });
            }}>Click me</button>
            <i className="inputMarker fa fa-angle-right" />
        </form>
    );
};
1 Answers

It looks like a permissions error. In the section called Data, select the corresponding table (project in your case?) and open permissions tab. There, you should set insert permissions to the corresponding role. In case you're not using custom roles, you must modify permissions to public role.

The key here is that the console uses admin role, so you can do everything in there.

Be careful, since modifying public role permissions might be risky.

Hasura permissions section

Related