@graphql-hive/core
Version:
20 lines (19 loc) • 665 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.atLeastOnceSampler = atLeastOnceSampler;
const sampling_js_1 = require("./sampling.js");
/**
* Every operation is reported at least once, but every next occurrence is decided by the sampler.
*/
function atLeastOnceSampler(config) {
const sampler = (0, sampling_js_1.dynamicSampling)(config.sampler);
const reportedKeys = new Set();
return function shouldInclude(context) {
const key = config.keyFn(context);
if (!reportedKeys.has(key)) {
reportedKeys.add(key);
return true;
}
return sampler(context);
};
}
;