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

2

11

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>
    );
};
Charlyncharm answered 15/3, 2020 at 4:1 Comment(2)
Do you have any permissions configured? Generally in Hasura console, the mutation works because you might have configured admin secret which gives full access. Also how is the apollo client configured? What are the headers being passed?Hemipterous
^Similar questions as above. In addition, seems like you may be missing array brackets [ ] when using plural insert_projects as such insert_projects(objects: [{...}]) { ... }. Relevant documentation: hasura.io/docs/1.0/graphql/manual/mutations/…Perak
T
21

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

Tasimeter answered 16/10, 2020 at 8:22 Comment(0)
S
0

I was getting the following error I finally figured out was granting permission

Error: field "typewallet" not found in type: 'recharge_register_bool_exp'

In Hasura database go to Permission and select a column you want to have insert permission

enter image description here

Smectic answered 30/6, 2023 at 8:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.