@graphql-mocks/network-playwright
Version:
Mock using graphql-mocks with Playwright
52 lines (51 loc) • 1.73 kB
JavaScript
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 playwrightHandler(graphqlHandler) {
return /*#__PURE__*/function () {
var _ref = _asyncToGenerator(function* (route, request) {
var body = request.postDataJSON();
if (!body) {
return route.fulfill({
status: 400,
json: {
errors: [{
message: "No request body provided in the request but it's required for querying with graphql-mocks"
}]
}
});
}
var {
query,
variables,
operationName
} = body;
if (!query) {
return route.fulfill({
status: 400,
json: {
errors: [{
message: "No \"query\" provided in request body but it's required for querying with graphql-mocks"
}]
}
});
}
var result = yield graphqlHandler.query(query, variables, {
playwright: {
request,
route
}
}, {
operationName
});
return route.fulfill({
status: 200,
json: result
});
});
return function (_x, _x2) {
return _ref.apply(this, arguments);
};
}();
}
export { playwrightHandler };
//# sourceMappingURL=index.mjs.map