{"size": 1631, "ext": "js", "max_stars_repo_path": "node_modules/@redwoodjs/web/dist/components/GraphQLHooksProvider.js", "max_stars_repo_name": "metanoiaweblabs/redwoodblog", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "node_modules/@redwoodjs/web/dist/components/GraphQLHooksProvider.js", "max_issues_repo_name": "metanoiaweblabs/redwoodblog", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "node_modules/@redwoodjs/web/dist/components/GraphQLHooksProvider.js", "max_forks_repo_name": "metanoiaweblabs/redwoodblog", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 29.125, "max_line_length": 101, "alphanum_fraction": 0.7510729614}
"use strict";

var _Object$defineProperty = require("@babel/runtime-corejs3/core-js/object/define-property");

var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;

_Object$defineProperty(exports, "__esModule", {
  value: true
});

exports.useQuery = useQuery;
exports.useMutation = useMutation;
exports.GraphQLHooksProvider = exports.GraphQLHooksContext = void 0;

var _react = _interopRequireDefault(require("react"));

const GraphQLHooksContext = _react.default.createContext({
  useQuery: () => {
    throw new Error('You must register a useQuery hook via the `GraphQLHooksProvider`');
  },
  useMutation: () => {
    throw new Error('You must register a useMutation hook via the `GraphQLHooksProvider`');
  }
});

exports.GraphQLHooksContext = GraphQLHooksContext;

/**
 * GraphQLHooksProvider stores standard `useQuery` and `useMutation` hooks for Redwood
 * that can be mapped to your GraphQL library of choice's own `useQuery`
 * and `useMutation` implementation.
 *
 * @todo Let the user pass in the additional type for options.
 */
const GraphQLHooksProvider = ({
  useQuery,
  useMutation,
  children
}) => {
  return /*#__PURE__*/_react.default.createElement(GraphQLHooksContext.Provider, {
    value: {
      useQuery,
      useMutation
    }
  }, children);
};

exports.GraphQLHooksProvider = GraphQLHooksProvider;

function useQuery(query, options) {
  return _react.default.useContext(GraphQLHooksContext).useQuery(query, options);
}

function useMutation(mutation, options) {
  return _react.default.useContext(GraphQLHooksContext).useMutation(mutation, options);
}