"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.graphql = void 0;

var _shopify = require("../helpers/shopify");

var _utils = require("../helpers/utils");

const graphql = async (req, res, config) => (0, _utils.handler)(_utils.onlyPOST, _utils.hasShopHeaders, _utils.hasBody, async data => {
  const {
    accessToken,
    graphqlEndpoint
  } = (0, _shopify.getShopifyHeaders)(data);

  try {
    const response = await (0, _shopify.queryShopifyGraphql)(res, graphqlEndpoint, accessToken, data.body);
    return response;
  } catch (err) {
    console.log(err.response && err.response.data.errors || err.message);
    return res.status(200).json({
      status: "error",
      body: err.response && err.response.data.errors
    });
  }
})(req, res, config);

exports.graphql = graphql;
//# sourceMappingURL=graphql.js.map