import { useState, useCallback, useEffect, useMemo } from "react";
const useJsonMemo = (value) => {
  const json = useMemo(() => JSON.stringify(value), [value]);
  return useMemo(() => value, [json]);
};
const useQuery = (client, query, variables, apiToken) => {
  const [state, setState] = useState({
    state: "loading"
  });
  const vars = useJsonMemo(variables);
  const refetch = useCallback(async () => {
    setState({ state: "loading" });
    try {
      const response = await client.sendRequest(query, {
        variables: vars,
        apiTokenOverride: apiToken
      });
      setState({
        ...response,
        state: "success"
      });
    } catch (e) {
      setState({ state: "error", error: e });
    }
  }, [client, query, vars, apiToken]);
  useEffect(() => {
    refetch();
  }, [refetch]);
  return useMemo(() => ({ state, refetch }), [state, refetch]);
};
export {
  useQuery
};
//# sourceMappingURL=useQuery.js.map
