Skip to content

Commit

Permalink
fix(main in package selecting correct folder): fix in main so that it…
Browse files Browse the repository at this point in the history
… is usable within your project
  • Loading branch information
kennetpostigo committed Nov 17, 2015
1 parent 5d55cb9 commit 9cf087d
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 3 deletions.
13 changes: 13 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.reachWithDispatch = exports.reachGraphQL = undefined;

var _reachGraphQL = require('./reachGraphQL.js');

var _reachWithDispatch = require('./reachWithDispatch.js');

exports.reachGraphQL = _reachGraphQL.reachGraphQL;
exports.reachWithDispatch = _reachWithDispatch.reachWithDispatch;
47 changes: 47 additions & 0 deletions dist/reachGraphQL.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"use strict";

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

var _transport = require("./utils/transport.js");

require("babel-polyfill");

/**
* [reachGraphQL Makes queres or mutations against GraphQL]
* @param {[String]} path [path to the GraphQL server]
* @param {[Object]} query [The query that GraphQL will use to fetch your data]
* @param {[object]} queryParams = {} [should contain object with different query params]
* @return {[Object]} [Data that was queried or qutated]
*/
function reachGraphQL(path, query) {
var queryParams = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];

return function _callee() {
var response;
return regeneratorRuntime.async(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
_context.prev = 0;
_context.next = 3;
return regeneratorRuntime.awrap((0, _transport.transport)(path, query, queryParams));

case 3:
response = _context.sent;
return _context.abrupt("return", response.data);

case 7:
_context.prev = 7;
_context.t0 = _context["catch"](0);

console.log(_context.t0);

case 10:
case "end":
return _context.stop();
}
}, null, this, [[0, 7]]);
};
}
52 changes: 52 additions & 0 deletions dist/reachWithDispatch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"use strict";

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

var _transport = require("./utils/transport.js");

require("babel-polyfill");

/**
* [reachWithDispatch description]
* @param {[String]} path [path to the GraphQL server]
* @param {[Object]} query [The query that GraphQL will use to fetch your data]
* @param {[object]} queryParams = {} [should contain object with different query params]
* @param {[type]} actionCreator = ( [The actionCreator to dispatch]
* @return {[function]} [dispatch to store]
*/
function reachWithDispatch(path, query) {
var queryParams = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
var actionCreator = arguments.length <= 3 || arguments[3] === undefined ? function () {} : arguments[3];

return function _callee(dispatch) {
var response;
return regeneratorRuntime.async(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
_context.prev = 0;
_context.next = 3;
return regeneratorRuntime.awrap((0, _transport.transport)(path, query, queryParams));

case 3:
response = _context.sent;

dispatch(actionCreator(response.data));
_context.next = 10;
break;

case 7:
_context.prev = 7;
_context.t0 = _context["catch"](0);

console.log(_context.t0);

case 10:
case "end":
return _context.stop();
}
}, null, this, [[0, 7]]);
};
}
38 changes: 38 additions & 0 deletions dist/utils/transport.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
'use strict';

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

var _isomorphicFetch = require('isomorphic-fetch');

var _isomorphicFetch2 = _interopRequireDefault(_isomorphicFetch);

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

function transport(path, query) {
var queryParams = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];

var url = path;
return new Promise(function (resolve, reject) {
(0, _isomorphicFetch2.default)(url, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
query: query,
queryParams: queryParams
})
}).then(function (res) {
return res.json();
}).then(function (response) {
if (response.errors) {
return reject(response.errors);
}
return resolve(response.data);
}).catch(response.error);
});
}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"name": "react-reach",
"version": "0.0.3",
"description": "A small library for react to communicate with GraphQL",
"main": "src/index.js",
"main": "dist/index.js",
"scripts": {
"prebuild": "rm -rf dist && mkdir dist",
"build": "babel src/index.js -o dist/index.js",
"prebuild": "rm -rf dist && mkdir dist && mkdir dist/utils",
"build": "babel src/index.js -o dist/index.js && babel src/reachGraphQL.js -o dist/reachGraphQL.js && babel src/reachWithDispatch.js -o dist/reachWithDispatch.js && babel src/utils/transport.js -o dist/utils/transport.js",
"commit": "git-cz",
"test": "mocha test/reachGraphQL.spec.js -w --compilers js:babel-core/register",
"test:single": "mocha test/reachGraphQL.spec.js --compilers js:babel-core/register",
Expand Down

0 comments on commit 9cf087d

Please sign in to comment.