"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const react = require("react");
const useMutation = (client, query, apiToken, headers) => {
  const [state, setState] = react.useState({
    state: "initial"
  });
  const cb = react.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];
};
exports.useMutation = useMutation;
//# sourceMappingURL=useMutation.cjs.map
