apollo-codegen-core
Version:
Core generator APIs for Apollo Codegen
26 lines • 1.12 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateOperationId = void 0;
const collectFragmentsReferenced_1 = require("./collectFragmentsReferenced");
const crypto_1 = require("crypto");
function generateOperationId(operation, fragments, fragmentsReferenced) {
if (!fragmentsReferenced) {
fragmentsReferenced = (0, collectFragmentsReferenced_1.collectFragmentsReferenced)(operation.selectionSet, fragments);
}
const sourceWithFragments = [
operation.source,
...Array.from(fragmentsReferenced).map((fragmentName) => {
const fragment = fragments[fragmentName];
if (!fragment) {
throw new Error(`Cannot find fragment "${fragmentName}"`);
}
return fragment.source;
}),
].join("\n");
const hash = (0, crypto_1.createHash)("sha256");
hash.update(sourceWithFragments);
const operationId = hash.digest("hex");
return { operationId, sourceWithFragments };
}
exports.generateOperationId = generateOperationId;
//# sourceMappingURL=generateOperationId.js.map
;