@graphql-mocks/network-playwright
Version:
Mock using graphql-mocks with Playwright
47 lines (45 loc) • 1.05 kB
JavaScript
;
function playwrightHandler(graphqlHandler) {
return async (route, request) => {
const 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`
}]
}
});
}
const {
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`
}]
}
});
}
const result = await graphqlHandler.query(query, variables, {
playwright: {
request,
route
}
}, {
operationName
});
return route.fulfill({
status: 200,
json: result
});
};
}
exports.playwrightHandler = playwrightHandler;
//# sourceMappingURL=index.js.map