'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _reason = require('reason');

var _reason2 = _interopRequireDefault(_reason);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

exports.default = {
  language: 'ReasonML',
  prismLanguage: 'reason',
  name: 'bs-fetch',
  options: [],
  generate: function generate(_ref) {
    var serverUrl = _ref.serverUrl,
        variableName = _ref.variableName,
        operationType = _ref.operationType,
        operationName = _ref.operationName,
        operation = _ref.operation,
        options = _ref.options;

    // snippet here
    return _reason2.default.printRE(_reason2.default.parseRE('\nlet serverUrl = "' + serverUrl + '"\n\nlet ' + variableName + ' = [%graphql\n{|\n' + operation + '\n|}\n]\n\nlet payload = Js.Dict.empty();\nJs.Dict.set(payload, "' + operationType + '", Js.Json.string(' + variableName + '));\n\nJs.Promise.(\n  Fetch.fetch(serverUrl,\n    Fetch.RequestInit.make(\n      ~method_=Post,\n      ~body=Fetch.BodyInit.make(Js.Json.stringify(Js.Json.object_(payload))),\n      ~headers=Fetch.HeadersInit.make({"Content-Type": "application/json"}),\n      ()\n    )\n  )\n  |> then_(Fetch.Response.json)\n  |> then_(json => print_endline(json) |> resolve)\n);'));
  }
};