graphql-stitch
Advanced tools
Comparing version 1.6.0 to 1.7.0
@@ -92,16 +92,28 @@ require("source-map-support").install(); | ||
}); | ||
exports.stitch = undefined; | ||
exports.stitch = stitch; | ||
var stitch = exports.stitch = function () { | ||
var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(_ref) { | ||
var _this = this; | ||
var _graphqlTools = __webpack_require__(3); | ||
var _ref$remotes = _ref.remotes, | ||
remotes = _ref$remotes === undefined ? [] : _ref$remotes, | ||
_ref$locals = _ref.locals, | ||
locals = _ref$locals === undefined ? [] : _ref$locals, | ||
resolvers = _ref.resolvers, | ||
preLink = _ref.preLink, | ||
postLink = _ref.postLink; | ||
var schemas; | ||
var _apolloLinkHttp = __webpack_require__(4); | ||
var _nodeFetch = _interopRequireDefault(__webpack_require__(5)); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } | ||
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } function _next(value) { step("next", value); } function _throw(err) { step("throw", err); } _next(); }); }; } | ||
function stitch(_x) { | ||
return _stitch.apply(this, arguments); | ||
} | ||
function _stitch() { | ||
_stitch = _asyncToGenerator( | ||
/*#__PURE__*/ | ||
regeneratorRuntime.mark(function _callee2(_ref) { | ||
var _ref$remotes, remotes, _ref$locals, locals, resolvers, preLink, postLink, fetchOptions, schemas; | ||
return regeneratorRuntime.wrap(function _callee2$(_context2) { | ||
@@ -111,5 +123,13 @@ while (1) { | ||
case 0: | ||
_context2.next = 2; | ||
return Promise.all(remotes.map(function () { | ||
var _ref3 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(remote) { | ||
_ref$remotes = _ref.remotes, remotes = _ref$remotes === void 0 ? [] : _ref$remotes, _ref$locals = _ref.locals, locals = _ref$locals === void 0 ? [] : _ref$locals, resolvers = _ref.resolvers, preLink = _ref.preLink, postLink = _ref.postLink, fetchOptions = _ref.fetchOptions; | ||
fetchOptions = _extends({ | ||
timeout: 10000 | ||
}, fetchOptions); | ||
_context2.next = 4; | ||
return Promise.all(remotes.map( | ||
/*#__PURE__*/ | ||
function () { | ||
var _ref2 = _asyncToGenerator( | ||
/*#__PURE__*/ | ||
regeneratorRuntime.mark(function _callee(remote) { | ||
var schema; | ||
@@ -120,5 +140,8 @@ return regeneratorRuntime.wrap(function _callee$(_context) { | ||
case 0: | ||
if (typeof remote === 'string') { | ||
remote = new _apolloLinkHttp.HttpLink({ uri: remote, fetch: _nodeFetch2.default }); | ||
remote = new _apolloLinkHttp.HttpLink({ | ||
uri: remote, | ||
fetch: _nodeFetch.default, | ||
fetchOptions: fetchOptions | ||
}); | ||
} | ||
@@ -129,2 +152,3 @@ | ||
} | ||
if (postLink) { | ||
@@ -139,26 +163,29 @@ remote = remote.concat(postLink); | ||
schema = _context.sent; | ||
return _context.abrupt('return', (0, _graphqlTools.makeRemoteExecutableSchema)({ schema: schema, link: remote })); | ||
return _context.abrupt("return", (0, _graphqlTools.makeRemoteExecutableSchema)({ | ||
schema: schema, | ||
link: remote | ||
})); | ||
case 7: | ||
case 'end': | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, _this); | ||
}, _callee, this); | ||
})); | ||
return function (_x2) { | ||
return _ref3.apply(this, arguments); | ||
return _ref2.apply(this, arguments); | ||
}; | ||
}())); | ||
case 2: | ||
case 4: | ||
schemas = _context2.sent; | ||
return _context2.abrupt('return', (0, _graphqlTools.mergeSchemas)({ | ||
schemas: [].concat(_toConsumableArray(schemas), _toConsumableArray(locals)), | ||
return _context2.abrupt("return", (0, _graphqlTools.mergeSchemas)({ | ||
schemas: _toConsumableArray(schemas).concat(_toConsumableArray(locals)), | ||
resolvers: resolvers | ||
})); | ||
case 4: | ||
case 'end': | ||
case 6: | ||
case "end": | ||
return _context2.stop(); | ||
@@ -169,22 +196,5 @@ } | ||
})); | ||
return _stitch.apply(this, arguments); | ||
} | ||
return function stitch(_x) { | ||
return _ref2.apply(this, arguments); | ||
}; | ||
}(); | ||
var _graphqlTools = __webpack_require__(3); | ||
var _apolloLinkHttp = __webpack_require__(4); | ||
var _nodeFetch = __webpack_require__(5); | ||
var _nodeFetch2 = _interopRequireDefault(_nodeFetch); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } | ||
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } | ||
/***/ }), | ||
@@ -191,0 +201,0 @@ /* 3 */ |
{ | ||
"name": "graphql-stitch", | ||
"version": "1.6.0", | ||
"version": "1.7.0", | ||
"description": "inspect and stitch remote graphql schemas with local ones", | ||
@@ -13,3 +13,3 @@ "main": "dist/bundle.js", | ||
"watch": "npm-run-all --parallel build:watch test:watch", | ||
"test": "mocha tests/ --require babel-core/register --require babel-polyfill --recursive", | ||
"test": "mocha tests/ --require babel-register --require babel-polyfill --recursive", | ||
"test:watch": "yarn test -- --watch", | ||
@@ -19,9 +19,13 @@ "prepublishOnly": "yarn run build" | ||
"devDependencies": { | ||
"babel-core": "^6.26.0", | ||
"@babel/core": "^7.0.0-beta.38", | ||
"@babel/plugin-proposal-class-properties": "^7.0.0-beta.38", | ||
"@babel/plugin-proposal-object-rest-spread": "^7.0.0-beta.38", | ||
"@babel/plugin-proposal-optional-chaining": "^7.0.0-beta.38", | ||
"@babel/preset-env": "^7.0.0-beta.38", | ||
"@babel/preset-flow": "^7.0.0-beta.38", | ||
"apollo-link": "^1.0.7", | ||
"babel-eslint": "^8.0.2", | ||
"babel-loader": "^7.1.2", | ||
"babel-loader": "^8.0.0-beta.0", | ||
"babel-minify-webpack-plugin": "^0.2.0", | ||
"babel-preset-env": "^1.6.1", | ||
"babel-preset-flow": "^6.23.0", | ||
"babel-webpack": "^1.0.0", | ||
"babel-register": "^7.0.0-beta.3", | ||
"chai": "^4.1.2", | ||
@@ -36,3 +40,2 @@ "eslint-plugin-class-property": "^1.0.6", | ||
"dependencies": { | ||
"apollo-link": "^1.0.7", | ||
"apollo-link-context": "^1.0.3", | ||
@@ -39,0 +42,0 @@ "apollo-link-http": "^1.3.0", |
@@ -5,4 +5,9 @@ import { makeRemoteExecutableSchema, mergeSchemas, introspectSchema } from 'graphql-tools'; | ||
export async function stitch({ remotes = [], locals = [], resolvers, preLink, postLink }) { | ||
export async function stitch({ remotes = [], locals = [], resolvers, preLink, postLink, fetchOptions }) { | ||
fetchOptions = { | ||
timeout: 10000, | ||
...fetchOptions | ||
}; | ||
const schemas = await Promise.all( | ||
@@ -12,3 +17,3 @@ remotes.map(async remote => { | ||
if (typeof remote === 'string') { | ||
remote = new HttpLink({ uri: remote, fetch }); | ||
remote = new HttpLink({ uri: remote, fetch, fetchOptions }); | ||
} | ||
@@ -15,0 +20,0 @@ |
@@ -5,2 +5,3 @@ | ||
import { stitch } from '../dist/bundle'; | ||
import { ApolloLink } from 'apollo-link'; | ||
@@ -31,2 +32,31 @@ it('should stitch remote schemas', async function () { | ||
it('should accept resolvers'); | ||
it('should apply preLink and postLink to all remotes'); | ||
it('should apply preLink and postLink to all remotes', async function () { | ||
this.timeout(10000); | ||
let preLinkRun = false; | ||
const preLink = new ApolloLink((operation, forward) => { | ||
preLinkRun = true; | ||
return forward(operation); | ||
}); | ||
const schema = await stitch({ remotes: ['http://fake.graphql.guru/graphql'], preLink }); | ||
const query = | ||
`{ | ||
Fake { | ||
_id | ||
firstName | ||
lastName | ||
} | ||
}`; | ||
const { data, errors } = await graphql(schema, query); | ||
expect(preLinkRun).to.equal(true); | ||
expect(errors).not.to.be.ok; | ||
expect(data).to.have.nested.property('Fake._id'); | ||
expect(data).to.have.nested.property('Fake.firstName'); | ||
expect(data).to.have.nested.property('Fake.lastName'); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
161882
5
295
18
- Removedapollo-link@^1.0.7