"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.maskOperation = maskOperation;
const utilities_1 = require("@apollo/client/utilities");
const environment_1 = require("@apollo/client/utilities/environment");
const invariant_1 = require("@apollo/client/utilities/invariant");
const maskDefinition_js_1 = require("./maskDefinition.cjs");
const utils_js_1 = require("./utils.cjs");
/** @internal */
function maskOperation(data, document, cache) {
    if (!cache.fragmentMatches) {
        if (environment_1.__DEV__) {
            (0, utils_js_1.warnOnImproperCacheImplementation)();
        }
        return data;
    }
    const definition = (0, utilities_1.getOperationDefinition)(document);
    (0, invariant_1.invariant)(definition, 47);
    if (data == null) {
        // Maintain the original `null` or `undefined` value
        return data;
    }
    return (0, maskDefinition_js_1.maskDefinition)(data, definition.selectionSet, {
        operationType: definition.operation,
        operationName: definition.name?.value,
        fragmentMap: (0, utilities_1.createFragmentMap)((0, utilities_1.getFragmentDefinitions)(document)),
        cache,
        mutableTargets: new WeakMap(),
        knownChanged: new WeakSet(),
    });
}
//# sourceMappingURL=maskOperation.cjs.map
