Uncaught (in promise) ApolloError: Response not successful: Received status code 400

63 Views Asked by At

I'm new to Apolle Client. My problem is that im trying to use a mutation to post to hygraph. My server is running and trying to post it and it does give me error code 400

My mutation code

const CREATE_INVENTORY = gql`
  mutation createInventory($name: String!, $count: Int!, $width: Float, $length: Float!) {
  createInventory(data: {name: $name, count: $count, length: $length, width: $width}) {
    id
    name
    length
    width
    count
  }
}
`;

This is my code that should post to sql statement


const [createInventoryMutation, {data,loading, error}] = useMutation(CREATE_INVENTORY);

  const handleImageChange = (e) => {
    const file = e.target.files[0];
    setImage(file);
  };
  if (loading) return 'Submitting...';
  if (error) return `Submission error! ${error.message}`;

    return (
      <form onSubmit={e => {
        e.preventDefault();
        console.log('submitting' , name , count , width , length);
        createInventoryMutation({ variables: { name, count, width, length } });
      }}>
        <label>Name:
          <input
            type="text" 
            value={name}
            onChange={(e) => setName(e.target.value)}
          />
        </label>
        
        <label>Count:
          <input
            type="number" 
            value={count}
            onChange={(e) => setCount(e.target.value)}
          />
        </label>  
        <label>Width:
          <input
            type="text" 
            value={width}
            onChange={(e) => setWidth(e.target.value)}
          />
        </label>
        <label>Height:
          <input
            type="text" 
            value={length}
            onChange={(e) => setLength(e.target.value)}
          />
        </label>

        <label>Image:
          <input className='file-image'
            type="file" 
            onChange={handleImageChange}
          />
        </label> 

        <button className='add-users-from' type="submit">
              Add Users<span>+</span>
          </button>
      </form>
    )
}

My response should be that the item is posted

in my hygraph api playground my mutation does work so what could be the problem in my code?

0

There are 0 best solutions below