import { useState, useCallback } from "react";
const useMutation = (client, query, apiToken, headers) => {
  const [state, setState] = useState({
    state: "initial"
  });
  const cb = useCallback(async (variables) => {
    setState({
      state: "loading"
    });
    try {
      const response = await client.sendRequest(query, {
        variables,
        apiTokenOverride: apiToken,
        headers
      });
      setState({
        ...response,
        state: "success"
      });
      return response.data;
    } catch (e) {
      setState({
        state: "error",
        error: e
      });
      throw e;
    }
  }, [client, query, apiToken, headers]);
  return [cb, state];
};
export { useMutation };
//# sourceMappingURL=useMutation.js.map
