-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
577fccb
commit 5c91eeb
Showing
8 changed files
with
200 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
'use strict'; | ||
|
||
var _regenerator = require('babel-runtime/regenerator'); | ||
|
||
var _regenerator2 = _interopRequireDefault(_regenerator); | ||
|
||
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator'); | ||
|
||
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2); | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = reachGraphQL; | ||
|
||
var _transport = require('./utils/transport.js'); | ||
|
||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
|
||
/** | ||
* [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 mutated] | ||
*/ | ||
function reachGraphQL(path, query) { | ||
var _this = this; | ||
|
||
var queryParams = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2]; | ||
|
||
return (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee() { | ||
var response; | ||
return _regenerator2.default.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
_context.prev = 0; | ||
_context.next = 3; | ||
return (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(); | ||
} | ||
} | ||
}, _callee, _this, [[0, 7]]); | ||
})); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
'use strict'; | ||
|
||
var _regenerator = require('babel-runtime/regenerator'); | ||
|
||
var _regenerator2 = _interopRequireDefault(_regenerator); | ||
|
||
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator'); | ||
|
||
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2); | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = reachWithDispatch; | ||
|
||
var _transport = require('./utils/transport.js'); | ||
|
||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
|
||
/** | ||
* [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 _this2 = this; | ||
|
||
var queryParams = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2]; | ||
var actionCreator = arguments[3]; | ||
|
||
return function () { | ||
var ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee(dispatch) { | ||
var response; | ||
return _regenerator2.default.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
_context.prev = 0; | ||
_context.next = 3; | ||
return (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(); | ||
} | ||
} | ||
}, _callee, _this2, [[0, 7]]); | ||
})), | ||
_this = _this2; | ||
return function (_x2) { | ||
return ref.apply(_this, arguments); | ||
}; | ||
}(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
'use strict'; | ||
|
||
var _stringify = require('babel-runtime/core-js/json/stringify'); | ||
|
||
var _stringify2 = _interopRequireDefault(_stringify); | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = transport; | ||
|
||
var _isomorphicFetch = require('isomorphic-fetch'); | ||
|
||
var _isomorphicFetch2 = _interopRequireDefault(_isomorphicFetch); | ||
|
||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
|
||
/** | ||
* [transport creates call to server with isomorphic-fetch] | ||
* @param {[String]} path [url to hit with request] | ||
* @param {[Object]} query [The GraphQL query/mutation] | ||
* @param {[Object]} queryParams = {} [Params to pass into query] | ||
* @return {[Promise]} [Promise containing payload] | ||
*/ | ||
function transport(path, query) { | ||
var queryParams = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2]; | ||
|
||
return (0, _isomorphicFetch2.default)(path, { | ||
method: 'POST', | ||
headers: { | ||
'Accept': 'application/json', | ||
'content-type': 'application/json' | ||
}, | ||
body: (0, _stringify2.default)({ | ||
query: query, | ||
queryParams: queryParams | ||
}) | ||
}).then(function (response) { | ||
return response.json(); | ||
}).then(function (responseBody) { | ||
if (responseBody && responseBody.errors) { | ||
throw new Error(responseBody.errors); | ||
} | ||
return responseBody.data; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters