UNPKG

@graphql-mocks/network-nock

Version:

Mock using graphql-mocks with Nock

38 lines (37 loc) 1.6 kB
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); } function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; } function nockHandler(graphqlHandler, options) { var internalHandler = /*#__PURE__*/function () { var _ref = _asyncToGenerator(function* (_uri, requestBody) { var checkRequest = options === null || options === void 0 ? void 0 : options.checkRequest; var checkGraphQLResult = options === null || options === void 0 ? void 0 : options.checkGraphQLResult; var { query, operationName, variables } = typeof requestBody === 'string' ? JSON.parse(requestBody) : requestBody; var request = this.req; if (checkRequest) { checkRequest(request, requestBody); } var context = { nock: { request } }; var result = yield graphqlHandler.query(query, variables, context, { operationName }); if (checkGraphQLResult) { checkGraphQLResult(result); } return [200, result]; }); return function internalHandler(_x, _x2) { return _ref.apply(this, arguments); }; }(); return internalHandler; } export { nockHandler }; //# sourceMappingURL=index.mjs.map