Skip to content

Commit 9cf087d

Browse files
committed
fix(main in package selecting correct folder): fix in main so that it is usable within your project
1 parent 5d55cb9 commit 9cf087d

File tree

5 files changed

+153
-3
lines changed

5 files changed

+153
-3
lines changed

dist/index.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict';
2+
3+
Object.defineProperty(exports, "__esModule", {
4+
value: true
5+
});
6+
exports.reachWithDispatch = exports.reachGraphQL = undefined;
7+
8+
var _reachGraphQL = require('./reachGraphQL.js');
9+
10+
var _reachWithDispatch = require('./reachWithDispatch.js');
11+
12+
exports.reachGraphQL = _reachGraphQL.reachGraphQL;
13+
exports.reachWithDispatch = _reachWithDispatch.reachWithDispatch;

dist/reachGraphQL.js

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
"use strict";
2+
3+
Object.defineProperty(exports, "__esModule", {
4+
value: true
5+
});
6+
exports.reachGraphQL = reachGraphQL;
7+
8+
var _transport = require("./utils/transport.js");
9+
10+
require("babel-polyfill");
11+
12+
/**
13+
* [reachGraphQL Makes queres or mutations against GraphQL]
14+
* @param {[String]} path [path to the GraphQL server]
15+
* @param {[Object]} query [The query that GraphQL will use to fetch your data]
16+
* @param {[object]} queryParams = {} [should contain object with different query params]
17+
* @return {[Object]} [Data that was queried or qutated]
18+
*/
19+
function reachGraphQL(path, query) {
20+
var queryParams = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
21+
22+
return function _callee() {
23+
var response;
24+
return regeneratorRuntime.async(function _callee$(_context) {
25+
while (1) switch (_context.prev = _context.next) {
26+
case 0:
27+
_context.prev = 0;
28+
_context.next = 3;
29+
return regeneratorRuntime.awrap((0, _transport.transport)(path, query, queryParams));
30+
31+
case 3:
32+
response = _context.sent;
33+
return _context.abrupt("return", response.data);
34+
35+
case 7:
36+
_context.prev = 7;
37+
_context.t0 = _context["catch"](0);
38+
39+
console.log(_context.t0);
40+
41+
case 10:
42+
case "end":
43+
return _context.stop();
44+
}
45+
}, null, this, [[0, 7]]);
46+
};
47+
}

dist/reachWithDispatch.js

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
"use strict";
2+
3+
Object.defineProperty(exports, "__esModule", {
4+
value: true
5+
});
6+
exports.reachWithDispatch = reachWithDispatch;
7+
8+
var _transport = require("./utils/transport.js");
9+
10+
require("babel-polyfill");
11+
12+
/**
13+
* [reachWithDispatch description]
14+
* @param {[String]} path [path to the GraphQL server]
15+
* @param {[Object]} query [The query that GraphQL will use to fetch your data]
16+
* @param {[object]} queryParams = {} [should contain object with different query params]
17+
* @param {[type]} actionCreator = ( [The actionCreator to dispatch]
18+
* @return {[function]} [dispatch to store]
19+
*/
20+
function reachWithDispatch(path, query) {
21+
var queryParams = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
22+
var actionCreator = arguments.length <= 3 || arguments[3] === undefined ? function () {} : arguments[3];
23+
24+
return function _callee(dispatch) {
25+
var response;
26+
return regeneratorRuntime.async(function _callee$(_context) {
27+
while (1) switch (_context.prev = _context.next) {
28+
case 0:
29+
_context.prev = 0;
30+
_context.next = 3;
31+
return regeneratorRuntime.awrap((0, _transport.transport)(path, query, queryParams));
32+
33+
case 3:
34+
response = _context.sent;
35+
36+
dispatch(actionCreator(response.data));
37+
_context.next = 10;
38+
break;
39+
40+
case 7:
41+
_context.prev = 7;
42+
_context.t0 = _context["catch"](0);
43+
44+
console.log(_context.t0);
45+
46+
case 10:
47+
case "end":
48+
return _context.stop();
49+
}
50+
}, null, this, [[0, 7]]);
51+
};
52+
}

dist/utils/transport.js

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
'use strict';
2+
3+
Object.defineProperty(exports, "__esModule", {
4+
value: true
5+
});
6+
exports.transport = transport;
7+
8+
var _isomorphicFetch = require('isomorphic-fetch');
9+
10+
var _isomorphicFetch2 = _interopRequireDefault(_isomorphicFetch);
11+
12+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13+
14+
function transport(path, query) {
15+
var queryParams = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
16+
17+
var url = path;
18+
return new Promise(function (resolve, reject) {
19+
(0, _isomorphicFetch2.default)(url, {
20+
method: 'POST',
21+
headers: {
22+
'Accept': 'application/json',
23+
'Content-Type': 'application/json'
24+
},
25+
body: JSON.stringify({
26+
query: query,
27+
queryParams: queryParams
28+
})
29+
}).then(function (res) {
30+
return res.json();
31+
}).then(function (response) {
32+
if (response.errors) {
33+
return reject(response.errors);
34+
}
35+
return resolve(response.data);
36+
}).catch(response.error);
37+
});
38+
}

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
"name": "react-reach",
33
"version": "0.0.3",
44
"description": "A small library for react to communicate with GraphQL",
5-
"main": "src/index.js",
5+
"main": "dist/index.js",
66
"scripts": {
7-
"prebuild": "rm -rf dist && mkdir dist",
8-
"build": "babel src/index.js -o dist/index.js",
7+
"prebuild": "rm -rf dist && mkdir dist && mkdir dist/utils",
8+
"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",
99
"commit": "git-cz",
1010
"test": "mocha test/reachGraphQL.spec.js -w --compilers js:babel-core/register",
1111
"test:single": "mocha test/reachGraphQL.spec.js --compilers js:babel-core/register",

0 commit comments

Comments
 (0)