@graphql-mocks/network-nock
Version:
Mock using graphql-mocks with Nock
33 lines (31 loc) • 945 B
JavaScript
;
function nockHandler(graphqlHandler, options) {
const internalHandler = async function (_uri, requestBody) {
const checkRequest = options === null || options === void 0 ? void 0 : options.checkRequest;
const checkGraphQLResult = options === null || options === void 0 ? void 0 : options.checkGraphQLResult;
const {
query,
operationName,
variables
} = typeof requestBody === 'string' ? JSON.parse(requestBody) : requestBody;
const request = this.req;
if (checkRequest) {
checkRequest(request, requestBody);
}
const context = {
nock: {
request
}
};
const result = await graphqlHandler.query(query, variables, context, {
operationName
});
if (checkGraphQLResult) {
checkGraphQLResult(result);
}
return [200, result];
};
return internalHandler;
}
exports.nockHandler = nockHandler;
//# sourceMappingURL=index.js.map